How to get selected value from DataGrid ?

  • Thread starter Thread starter William Ryan
  • Start date Start date
hey guyz,

i got an answer. Just want to share with you..

DataGrid1(DataGrid1.CurrentRowIndex, 0)


Note that this does not work if the grid has been sorted. Instead use
the CurrencyManager.

=======================================================
//dgCusomters is the DataGrid
CurrencyManager cm;
cm = (CurrencyManager)dgCustomers.BindingContext[
dgCustomers.DataSource, dgCustomers.DataMember];
DataRow dr = ((DataRowView)cm.Current).Row;
=======================================================

'dr' now refers to the actual DataRow from the bound DataTable that is
currently selected in the grid.

--
Michael Lang, MCSD
See my .NET open source projects
http://sourceforge.net/projects/colcodegen (simple code generator)
http://sourceforge.net/projects/dbobjecter (database app code generator)
http://sourceforge.net/projects/genadonet ("generic" ADO.NET)
 
Hi,

I filled up DataGrid using dataset. I've two Columns CountryCode,
CountryName.

When the user double clicks on the grid, I need to show the selected row
values.

example: AU - Australia.

Can anyone give me simple example.

Thanks
 
hey guyz,

i got an answer. Just want to share with you..

DataGrid1(DataGrid1.CurrentRowIndex, 0)

Regards
ItsMe :)
 
Back
Top