DataGrid COntrol

F

FF

Hi all,
I want to know how I can retrive the selected row in a DataGrid control (Not
the row index)!
Thanks
FF
 
N

Nicholas Paldino [.NET/C# MVP]

FF,

Assuming it is bound to a data table, you can do this:

// Get the data source.
DataView dv = ((DataTable) dataGrid.DataSource).DefaultView;

// Get the row.
DataRowView rv = dv[dataGrid.CurrentRowIndex];

Of course you might want to check for the cases where there are no
records. This returns a data row view, which is the row of data, possibly
filtered based on row state.

Hope this helps.
 
F

Fouad Fahim

That's work fine!
Thank you,
FF

Nicholas Paldino said:
FF,

Assuming it is bound to a data table, you can do this:

// Get the data source.
DataView dv = ((DataTable) dataGrid.DataSource).DefaultView;

// Get the row.
DataRowView rv = dv[dataGrid.CurrentRowIndex];

Of course you might want to check for the cases where there are no
records. This returns a data row view, which is the row of data, possibly
filtered based on row state.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

FF said:
Hi all,
I want to know how I can retrive the selected row in a DataGrid control
(Not the row index)!
Thanks
FF
 

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