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 used the following code
If e.Record IsNot Nothing Then
e.Record.ExpansionIndicatorVisibility = Visibility.Visible
Else
e.Record.ExpansionIndicatorVisibility = Visibility.Hidden
End If
and get a " Message="Object reference not set to an instance of an object." Source="Infragistics3.Wpf.DataPresenter.v9.1"" error when I expand a parent (my hierarchy has two levels and not all of the top level has children).
Any ideas?
As a note Joe and Sandip... I consider this a bug. Is this being looked at as a possible hotfix? Expansion Indicators should automatically detect if child records are present and be visible. If no child records, then the indicator should not be visible.
Thanks,
Rod
I have been plugging away at this for a day and have come up with the following. I had real issues with this since I want to move records around and make the parent and child relationships different. Even though the code mentioned above worked after initial load, it didn't work for updates. Here what I came up with in addition to the code mentioned in the previous post.
void theDataGrid_RecordUpdated(object sender, RecordUpdatedEventArgs e) { Record parent = theDataGrid.Records[0] as Record;
if (parent.HasChildren) { parent.ResetExpansionIndicatorVisibility(); SetExpansionIndicator(parent); } else { parent.ExpansionIndicatorVisibility = Visibility.Hidden; } }
private void SetExpansionIndicator(Record parentDataRecord) { if (parentDataRecord.GetType() == typeof(DataRecord)) { DataRecord dr = parentDataRecord as DataRecord;
foreach (ExpandableFieldRecord child in dr.ChildRecords) { if (child.HasChildren) { child.ResetExpansionIndicatorVisibility(); SetExpansionIndicator(child as Record); } else { child.ExpansionIndicatorVisibility = Visibility.Hidden; } } }
if (parentDataRecord.GetType() == typeof(ExpandableFieldRecord)) { ExpandableFieldRecord dr = parentDataRecord as ExpandableFieldRecord; foreach (Record child in dr.ChildRecords) { if (child.HasChildren) { child.ResetExpansionIndicatorVisibility(); SetExpansionIndicator(child as Record); } else { child.ExpansionIndicatorVisibility = Visibility.Hidden; } } } }
I recently noticed the extra "+"'s too. Commenting out the line that sets it to visible seems to work for me now, though I haven't tested this extensively. Not sure why some of those child records would return true for HasChildren when they don't really have children.
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.