简体   繁体   中英

DataGridView in Xamarin for mobile app (Android/iOS)

I need to create an application where the main activity has to contain numerical data like in a DataGridView in windows form. I have to display a number of rows that can change over time depending on some calculation (but it will never be less than 8 rows) and 5 columns. Each cell of this table will contain a value. When using windows form I was using DataGridView for the purpose of displaying the data and I was able to programmatically add a new row if needed by using the command:

 myGridView.Rows.Add()

and to read the information in myGridView:

 foreach (DataGridViewRow row in myGridView.Rows)
 {
    if (row.Cells[1].Value != null) 
    // do something
 }

What is the best way to achieve this in Xamarin? I cannot see the exact same equivalent as DataGridView. Thanks for the help.

No, unfortunately there's not such thing in Xamarin.Forms (neither Xamarin.IOS or Xamarin.Android) and the main reason is that the native platforms (iOS and Android) do not have it as a native control.

In Xamarin.Forms there is a Grid control but its use is mainly for layouts and cannot be Databinded like the DataGridView.

The good thing is that you have everything you need to make one for your own. Subclass the Grid , add some binding properties and create custom renderer for each platform you want to support, you might have to do a little more than this but at least this could be a good start.

Note: I did a quick search for an open source project and this one looks very interesting. Take a look it might probably do the job you need.

I recently built my own data grid control for Xamarin Forms since I couldn't find one that met my needs. If you're still looking for a data grid control, I've published mine on Nuget and it is on Github. It's completely free to use. Let me know if it helps you out!

It is called the NoFrillsDataGrid.

Github: https://github.com/davepruitt/NoFrillsDataGrid

Nuget: https://www.nuget.org/packages/NoFrills.Xamarin.Forms/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM