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

select a row programatically

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

5 Replies

AD Administrator Syncfusion Team 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);
}
}
}


MB Manoj Bhaskarakurup 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


HA haneefm Syncfusion Team 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


MB Manoj Bhaskarakurup 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


HA haneefm Syncfusion Team 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

Loader.
Live Chat Icon For mobile
Up arrow icon