How to address fields on a selected row in a datagrid

  • Thread starter Thread starter X-Killer
  • Start date Start date
X

X-Killer

I've played around the datagrid control for some time and can't find any
"rows" or "columns" property within it. What is the easiest way to find out
the content of each fields of a selected row in a datagrid?
 
You should get hold of the data view the data grid uses. For that purpose,
use the code below:

CurrencyManager cm = (CurrencyManager)this.DataBindings[grid.DataSource,
grid.DataMember];
DataView view = (DataView)cm.List;

DataRowView rowView = view[cm.Position];

string firstName = rowView["FirstName"];
 
Thanks for you precious info., it's fixed now.

Dmitriy Lapshin said:
You should get hold of the data view the data grid uses. For that purpose,
use the code below:

CurrencyManager cm = (CurrencyManager)this.DataBindings[grid.DataSource,
grid.DataMember];
DataView view = (DataView)cm.List;

DataRowView rowView = view[cm.Position];

string firstName = rowView["FirstName"];

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

X-Killer said:
I've played around the datagrid control for some time and can't find any
"rows" or "columns" property within it. What is the easiest way to find out
the content of each fields of a selected row in a datagrid?
 
Back
Top