I have my gridview working with data tables for the data sources for both the master template and the child template. Can you tell me how to do two things?
1. I would like to set the width for that column that expands and collapses the child rows. (It has that [+] and [-] symbol in it.)
2. Is there a way to collapse the child rows for a parent row when I click to expand a different parent row?
Thank you,
Gary
6 Answers, 1 is accepted
I found a previous post regarding collapsing other rows and implemented this version of that:
private void gvPickLocations_ChildViewExpanding(object sender, ChildViewExpandingEventArgs e)
{
GridViewTemplate template = e.ParentRow.ViewTemplate;
foreach (GridViewRowInfo row in template.Rows)
{
if (row != e.ParentRow)
{
row.IsExpanded = false;
}
}
Can I also hide that [+] icon when the parent row has no child rows?
In my application, this gridview is essentially read only. Nothing is being added, edited, or deleted.
Thank you for writing.
Indeed, setting the row's IsExpanded property allows you managing whether a row is expanded or not.
I would recommend you to have a look at the following help article demonstrating how to hide the expander icons for parent rows that don't have any children: https://docs.telerik.com/devtools/winforms/gridview/cells/formating-examples/child-tabs
As to the width of the expander column, you can set the RadGridView.TableElement.GroupIndent property to the desired width.
I hope this information helps. Should you have further questions I would be glad to help.
Regards,
Dess
Progress Telerik
Dess,
Thank you. I'm working through the solution for the expander icons for the parent rows. My grid has one child template. I ran into two issues with the cell formatting method:
1.In this part of the code
else
if
(cell !=
null
)
{
GridViewHierarchyRowInfo hierarchyRow = (GridViewHierarchyRowInfo)((GridViewDetailsRowInfo)cell.RowInfo).Owner;
for
(
int
i = 0; i < cell.PageViewElement.Items.Count; i++)
{
I get an error because cell.PageViewElement is null (sometimes). So I added a test: else if (cell != null && cell.PageViewElement != null) to get around that.
2. When the grid is first displayed, none of the parent rows have the expander element visible. I have to click on the cell for each row and the expander element will become visible if that row has child rows.
I'm working though it but if you have additional information I would like to know about that.
Thank you,
Gary
I found a pattern that happens consistently concerning the expander images that are not visible when the grid is rendered.
The last parent row that should display the image doesn't. Parent rows above that row do display the image. If, after the form displays the gridview, I immediately execute the code to load the gridview's datasources again, all rows that should display the expander image do.
Thank you for writing back.
In case your hierarchical grid has only one child template, you don't have a tabbed view when expanding a parent row. That is why you obtain the exception. However, in this case you don't need to hide the child tabs because you are actually not expected to see them. I referred a wrong article in my previous post. Please excuse me for the misunderstanding. You just need to hide the expander sign "+" when no child rows are available. The following KB article demonstrates a sample code snippet how to achieve it: https://www.telerik.com/support/kb/winforms/gridview/details/hide-expand-collapse-image-in-hierarchical-radgridview
I hope this information helps. If you have any additional questions, please let me know.
Regards,
Dess
Progress Telerik