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: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

select a row programatically

Thread ID:

Created:

Updated:

Platform:

Replies:

60233 May 1,2007 12:19 AM UTC May 1,2007 11:17 PM UTC WinForms 5
loading
Tags: GridControl
Manoj Bhaskarakurup
Asked On May 1, 2007 12:19 AM UTC

Hi,

I want to select a row in a GridGroupingControl based on a value of a column in the grid. For ex, of I have a column as "number", I want to programatically select a row in the grid with a specific number.

Something like select a row with number = 1234

Thanks
Manoj

Administrator [Syncfusion]
Replied On May 1, 2007 09:25 AM UTC

You somehow have to find the records and then select them. Depending upon exactly what your datasource is, there may be more efficient ways to do this than just looping through all the records. But looping through the records should work. Here is code that will select all displayed records whose value in a column named A is 8.

private void button1_Click(object sender, EventArgs e)
{
this.gridGroupingControl1.Table.SelectedRecords.Clear();
foreach (GridRecord rec in this.gridGroupingControl1.Table.FilteredRecords)
{
if (rec.GetValue("A").Equals(8))
{
rec.SetSelected(true);
}
}
}

Manoj Bhaskarakurup
Replied On May 1, 2007 06:27 PM UTC

Hi,

I have a small change in the requirement. We are grouping the records in the grid by a column (for ex. column A). And I need to select a particular record in a specific group and the record is identified by another column value (for ex column B). That is I need to expand the group if it is collapsed and then select a record in that group.

Even if expanding a collapsed group is not possible, I am fine with that. I need to atleast highlight a row in a particular group even if it is collapsed, that is if the user expands the collapsed group then they should see a row highlighted.

Thanks
Manoj

haneefm [Syncfusion]
Replied On May 1, 2007 07:02 PM UTC

Hi Manoj,

This can be done by handling the GroupExpanded event of the grid and select the expanded records using the e.Group property from the GroupEventArgs. Here is a code snippet to show this.

private void gridGroupingControl1_GroupExpanded(object sender, GroupEventArgs e)
{
if( e.Group.Name == "GroupByColumnName"
&& e.Group.Category.ToString() == "CategoryValue" )
{
e.Group.ParentTable.SelectedRecords.Clear();
foreach(Record rec in e.Group.FilteredRecords)
{
if( rec.GetValue("B").Equals(10))
rec.SetSelected(true);
}
}
}

Best regards,
Haneef

Manoj Bhaskarakurup
Replied On May 1, 2007 11:01 PM UTC

Hi Haneef,

Thanks you, it works fine. Can you also tell me how to expand a group programatically.

Thanks
Manoj

haneefm [Syncfusion]
Replied On May 1, 2007 11:17 PM UTC

Hi Manoj,

Use the IsExpanded property to expand/collapse the group in grid. Here is a code snippet that shows you "How to access the particular group and expand it?".

// Using category to access the group and expand it.
this.gridGroupingControl1.Table.TopLevelGroup.Groups["row6 col1"].IsExpanded = true;;

//Or using index to access the group and expand it.
//this.gridGroupingControl1.Table.TopLevelGroup.Groups[6].IsExpanded = true;

Best regards,
Haneef

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.

Please sign in to access our forum

or the page will be automatically redirected to sign-in page in 10 seconds.

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

;