DataGrid selected rows

  • Thread starter Thread starter R Agam
  • Start date Start date
Hi,

DataGrid.SelectedIndex.

from MSDN:
Remarks
Use the SelectedIndex property to determine the index of the item selected
by the user in the DataGrid control. You can also use this property to
programmatically specify which item is selected in the DataGrid control.

To deselect an item in the DataGrid control, set this property to -1.

Hope this help,
 
Hi,

It;s a property of the Datagrid class :

DataGrid grid = new DataGrid()

grid.SelectedIndex = -1;

Hope this help,
 
To "reliably" do this (as a dg sort changes things.) You do this:
private Zone[] GetSelectedZones(DataGrid dg)
{
ArrayList al = new ArrayList();
CurrencyManager cm = (CurrencyManager)this.BindingContext[dg.DataSource,
dg.DataMember];
DataView dv = (DataView)cm.List;
for(int i = 0; i < dv.Count; ++i)
{
if(dg.IsSelected(i))
{
Console.WriteLine("Zone {0} selected.", i );
al.Add(dv.Row["Zone"]);
}
}
return (Zone[])al.ToArray(typeof(Zone));
}
See:
http://www.syncfusion.com/FAQ/WinForms/default.asp
 
Back
Top