Get DataGridView Cell Value on DataGridObj.SelectedRowsChanged when I fill the gridview dynamically with a DataTable and not with a class with getters and setters

62 views
Skip to first unread message

Anthony Rivera

unread,
Sep 3, 2014, 12:33:48 PM9/3/14
to eto-...@googlegroups.com
how can in get the a specific cell value on DataGridObj.SelectedRowsChanged event  when I fill the gridview dynamically with a DataTable?

Let's say for example I  selected a row that have this columns 

User_id, username, email, phone, ...

How ca in get the user_id value from the grid?

Thanks in advance! :D

curtis

unread,
Sep 15, 2014, 9:48:35 PM9/15/14
to eto-...@googlegroups.com
To get the selected items of a data grid, you can use the SelectedItems property, which will give you each of the selected items in your collection.

For example, if your DataStore is a collection of DataRow objects, then you can do:

foreach (var row in myGrid.SelectedItems.Cast<DataRow>())
{
  var id = row["user_id"];
  // do something with the id
}

Cheers!
Curtis.
Reply all
Reply to author
Forward
0 new messages