How to address fields on a selected row in a datagrid

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?
 
D

Dmitriy Lapshin [C# / .NET MVP]

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"];
 
X

X-Killer

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top