4 Answers, 1 is accepted
Hello, James,
RadGridView offers ChildViewExpanding event that triggers when the child view is about to be expanded or collapsed. This event can be canceled. You can use it in order to achieve your requirement and allow only one row to expand. An example is demonstrated below:
this.radGridView1.ChildViewExpanding += this.RadGridView1_ChildViewExpanding;
private void RadGridView1_ChildViewExpanding(object sender, ChildViewExpandingEventArgs e)
{
if (e.ParentRow.Index != 1)
{
e.Cancel = true;
}
}
I hope this helps. Should you have any other questions please let me know.
Regards,
Nadya
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.
Thanks for the reply, but this is exactly what I am looking for. I don't want to stop the user from expanding a row. What I would like to happen is for all rows except for the currently expanding row to collapse.
Any thoughts on how to achieve this?
Thanks again in advance,
Edit from my last post. What I meant to say is:
Thanks for the reply, but this is NOT exactly what I am looking for. I don't want to stop the user from expanding a row. What I would like to happen is for all rows except for the currently expanding row to collapse.
Any thoughts on how to achieve this?
Thanks again in advance,
Hello, James,
Thank you for providing additional information. If I understand you correctly you would like to be able to expand all rows, however, when one row is expanded the rest gets collapsed automatically. In this case, you should iterate the GridViewHierarchyRowInfos and collapse all except the current one. You can refer to the following help article: https://docs.telerik.com/devtools/winforms/controls/gridview/hierarchical-grid/how-to/iterating-the-child-rows-collection-of-a-chosen-parent-row-in-hierarchy-radgridview
I prepared an example:
private void RadGridView1_ChildViewExpanded(object sender, ChildViewExpandedEventArgs e)
{
if (e.ChildViewInfo != null)
{
CollapseRowsExceptOne();
}
}
void CollapseRowsExceptOne()
{
foreach (GridViewRowInfo row in radGridView1.Rows)
{
GridViewHierarchyRowInfo hierarchyRow = row as GridViewHierarchyRowInfo;
if (hierarchyRow != null && hierarchyRow.IsCurrent == false)
{
hierarchyRow.IsExpanded = false;
}
}
}
Note, this is a sample demonstration. Feel free to modify it in a way to suit your requirements the best.
I hope this helps. If you need further assistance do not hesitate to contact me.
Regards,
Nadya
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.