[Resolved][2.0] Getting DataGridView data
Is there any way to "get" the data displayed in the datagridview control?
The underlying data structure is different for different screens, and I want to use the same data-getting for a handful of datagridviews.
There does not seem to be a straightforward way to navigate the cells to get their values.
Re: [2.0] Getting DataGridView data
The Item property of the DataGridView returns a cell by column name or index and row index. Had you read the help topic for the DataGridView member listing as you should have you'd have seen this description:
Quote:
Overloaded. Gets or sets the cell located at the intersection of the specified row and column.
Once you've got the cell you want you can access its Value or FormattedValue property. Having said that, if your grid is bound then I'd suggest working with the data source rather than the grid is most situations. If you've bound your grid to a BindingSource, as is recommended, then you can get the bound data from that. If the BindingSource is bound to a DataTable then its items are DataRowView objectsw, from which you can get the data directly or from the corresponding DataRow, which is exposed via its Row property.
Re: [2.0] Getting DataGridView data
I actually had been in the help section a couple of times, but never picked up on how to get info back out.
I stumbled upon the .rows collection which would have been infinatly more apparent to me if I had recalled that C# uses [] instead of () for indexing items.
It is not a bound data source, and it's a cluster you-know-what to pick out what I need from the Data. Anyways, seems I'm good to go.