How to get the index selected in the datagrid table

  • Thread starter Thread starter anant
  • Start date Start date
A

anant

How to get the index selected in the datagrid table which contains the employees table information ,on getting the index who to update the record at that index in to other table
 
Hi!

If you want to get current row index from datagrid and then get this
row from DataTable you can use following code:

private BindingManagerBase bindingManagerBase;

public Form1()
{
......
......
//-----get binding context here-------------//
bindingManagerBase = dataGrid1.BindingContext[dataTable1];
}

//---------then you can use bindingManagerBase.Position to get row from
DataTable. Better to get row form DataView, because rows in DataGrid
can be sorted, filtered and etc...
void SomeMethod()
{
dataTable1.DefaultView[bindingManagerBase.Position]["column1"] = 6;
}

Best Regards, Michael Milonov
http://www.snotratech.com
 
Back
Top