1

looking for some guidance on how best to approach this problem.

I've got a requirement to create a data grid that shows some parent rows and on each parent row we have a expand / collapse button. When clicked this button will cause some related child rows to be displayed under the parent row.

I've implemented this by using a rowdetailstemplate on the parent data grid that when expanded shows another datagrid that then displays the related child rows. This earlier question Displaying hierarchal parent child data in WPF DataGrid shows the details..

This works ok but has the problem that each parent row effectively has a seperate datagrid for the children, so things like navigating with the keyboard don't work too well, as the child rowdetails area is skipped over, the only thing we navigate is the parent.

Other problems are when we select child rows with the mouse we end up with several rows that are highlighted as selected. This is understandable as each grid is a seperate control.

The aim is to treat the child rows the same as the parent rows, in terms of selecting , navigating etc.

Does anybody have any pointers or guidance as to how to solve this problem?

Thanks

Community
  • 1
  • 1
Mark D
  • 279
  • 1
  • 7
  • 17
  • does the user need to be able to edit the child row data? – Jake Berger Mar 19 '12 at 21:21
  • so, the user can't edit the data, but it they need to be able to navigate to each individual data item? why? copy/pasting? – Jake Berger Mar 20 '12 at 13:46
  • they have to be able to set focus to the row to allow them to effectively select the row to trigger an action, firing up a popup style editing form etc. – Mark D Mar 20 '12 at 16:04
  • This might help get you started https://www.wpf-tutorial.com/datagrid-control/details-row/ – Agrejus Nov 20 '18 at 19:33

1 Answers1

1

WPF DataGrid cannot be used for hierarchical tree view style representation that easily. There is a TreeListView control but it isnt as sophisticated WPF datagrid in terms of virtualization, editing, cell \ row selection etc. But given that your data grid will be readonly and your selection is row-wise you can apply styles to this control to make it look like its a WPF data grid.

WPF-it
  • 19,625
  • 8
  • 55
  • 71
  • yes the data is readonly, but could have a largish number of rows / columns so I've been staying away from the treeview due to the lack of virtualization. – Mark D Mar 20 '12 at 08:58
  • You may have to go with 3rd party gruid like infragistics. Just curious to ask, how many rows can your hierarchy have and how many levels deep? – WPF-it Mar 20 '12 at 09:08
  • Hi, my boss isn't keen on third party controls, but I'm like you why reinvent the wheel. The data is only one level deep, parent to many children. Could be 2000 rows plus 40 columns. – Mark D Mar 20 '12 at 09:30