I have a hierarchical dataset bound as the datasource to a datagrid. The rows in the parent table show up in the grid, and all the rows have an expansion indicator on their left. However, some of the rows in my datasource do not have corresponding rows in the child table. For these, I don't want the expansion indicator to appear, so that the user can easily tell which rows have children and which do not. Is this possible?
thanks,
- Kam
I just figured this out, and figure I'd post it here in case anyone else was interested:
Handle the InitializeRecord event, and in your handler set the Record's ExpansionIndicatorVisibility propery according:
e.g.
private void OnInitializeRecord(object sender, InitializeRecordEventArgs e) { if (e.Record != null) { if (e.Record.HasChildren) e.Record.ExpansionIndicatorVisibility = Visibility.Visible; else e.Record.ExpansionIndicatorVisibility = Visibility.Hidden; }
}
I was excited about this post, but I've since had to remove this trick from my code. I found that while it helped under some situations (where the indicator was falsely appearing), it actually CAUSED the indicator to appear in other situations (where there was no indicator).
In other words, on my child tables, I was seeing an extra layer of "+" when NOTHING should have appeared.
I haven't had time to investigate this, but I suspect an additional check of some sort is required in the above code snippet to detect whether the property should be manipulated at all. If anyone has some insight, I'd like to hear it, because I have all sorts of "+" symbols where there are no children, which is yucky.