DataGrid selected rows

I

Ignacio Machin

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,
 
I

Ignacio Machin

Hi,

It;s a property of the Datagrid class :

DataGrid grid = new DataGrid()

grid.SelectedIndex = -1;

Hope this help,
 
W

William Stacey

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
 

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