Is it possible to have a pure hierarchical wpf data grid? Now there are 3 possible solutions dicussed over the internet ...
- GroupStyle
- TreeListView instead of DataGrid
- RowDetailsTemplate
Now all 3 are not useful in my case as they each have limitations.
GroupStyle
provides grouped row presenters but their parent is simply GroupItem
. This is where my data source is different. In my case the parent of the grouped items will be of the same type of item.
e.g. Folder
class has List<Folders> children
. So the parent of child folders is of type Folder
itself.
RowDetailsTemplate
would need me to host another datagrid that is bound to Children
, but that would mean it would have its own column headers and what I want is the children to share the same column view of the parent DataGrid, just like they do in TreeListView
.
And for TreeListView
, thats what I am using right now, but its problem is ...
It looses virtualization and it is not a datagrid
:-)
I was thinking like some attached behavior that toggles the hierarchy view for the data grid like...
<DataGrid HierarchicalBehavior.HierarchyPath="Children" ... />
Where Children
is a property of type IEnumerable
under each item.
I hope you guys understand what I am getting at.
Any ideas?
I could implement this finally. The code is too big to post. But if anyone's looking for the solution, do send an email to me.
Bascially I did the following things...
INotifyPropertyChanged
and also following extra properties via a base class ..Parent => Parent item which this item is child for. Readonly.
HasHierarchy => False when hierarchy children is null or empty. Writeable.
IsItemVisible => Current Visibility. Writeable.
IsBranchVisible => False if any ancestor has IsExpanded = false or IsItemVisible = false. ReadOnly but notifyable.
IsExpanded => If the item is expanded. Writeable.
Voala! It works like charm. Fast due to PLINQ.