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. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Decting which Row is selected

Thread ID:

Created:

Updated:

Platform:

Replies:

54797 Jan 17,2007 08:13 PM UTC Jan 18,2007 11:05 PM UTC WinForms 4
loading
Tags: GridControl
Charlie Mao
Asked On January 17, 2007 08:13 PM UTC

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

Administrator [Syncfusion]
Replied On 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

Charlie Mao
Replied On 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

Administrator [Syncfusion]
Replied On 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

Charlie Mao
Replied On January 18, 2007 11:05 PM UTC

Hey Haneef,

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

Charlie

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;