We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Decting which Row is selected

Hi,

I was wondering if anyone could provide me with a code snippet of detecting which row was selected using a databound grid. Thanks.

Charlie

4 Replies

AD Administrator Syncfusion Team January 17, 2007 08:42 PM UTC

Hi Charlie,

You can use the SelectionChanged event of the GridModel to detect the selected rows in a grid. Here is a code snippet to show this.

//Form Load event
this.gridDataBoundGrid1.ListBoxSelectionMode = SelectionMode.MultiExtended; //Set the SelectionMode.
this.gridDataBoundGrid1.Model.SelectionChanged +=new GridSelectionChangedEventHandler(Model_SelectionChanged);//Hook the event.

private void Model_SelectionChanged(object sender, GridSelectionChangedEventArgs e)
{
if( e.Range.IsRows)//For Row Selection.......only
{
DataTable dt = this.gridDataBoundGrid1.DataSource as DataTable;
for(int i = e.Range.Top ;i<=e.Range.Bottom;i++)
{
int pos = this.gridDataBoundGrid1.Binder.RowIndexToListManagerPosition(i);
Console.WriteLine("{0}th has been selected",pos);
Console.WriteLine("First Column Value : " + dt.Rows[pos][0]);
}
}
}

Best Regards,
Haneef


CM Charlie Mao January 17, 2007 09:57 PM UTC

Hey Haneef,

Thanks for the reponse. Is this the only way to detect which row is highlighted. Or maybe you can offer a better way. What I am trying to do is be able to edit a single cell within the datagrid. What i want is when I double click on a particular cell it pops up a window which I can then edit that cell. I thought about just detecting the entire row, but if syncfusion provides a better way, then that would be great. Thanks again.

Charlie


AD Administrator Syncfusion Team January 17, 2007 10:54 PM UTC

Hi Charlie,

Please try the sample and let me know if you are trying something different.
GDBGDataRow.zip

Best Regards,
Haneef


CM Charlie Mao January 18, 2007 11:05 PM UTC

Hey Haneef,

Thank you. This is exactly what I was looking for.

Charlie

Loader.
Live Chat Icon For mobile
Up arrow icon