DataGridView hierarchical rows

0
0

Hi guys,

I’m trying to use the new hierarchical rows of DGV, which I have been anticipating for long! In my case, I have a list of “therapies” assigned to a patient. Each therapy has a type and a therapist. From time to time, a certain therapist changes and a new therapy of the same type is created with the new therapist. I want to show only one therapy of each type (the latest one with the current therapist) as my parent row and when expanding show the previous therapies of the same type (with the previous therapists).

I have a couple of questions:

  1. First of all, what’s the idea? Am I doing the right thing? Are the child rows supposed to be of the same object (my case)  or are they of a different  object like, e.g., parent rows being order headers and each of them when expanded showing the order details (items)?
  2. I’m using them assuming that the first is true. How am I supposed to populate my grid? I tried loading all the rows (parent and children) first and then in the BindingComplete event loop over rows, find the parent ones and for each parent find the corresponding children and set their .Parent property accordingly. Is this the way to go? I am having errors of the type “parent row cannot follow child row” or something like this.
  3. When a row becomes parent, an “expand” icon shows up in the first column with the value of this column shifted to the right. However, the values of this first column for the children rows do not show any more. Is this intented and I should add a “dummy” first column to accommodate the “expand” icon?

A usage example would be great !

Thanks a lot for this addition!

Best,
Alex

  • You must to post comments
0
0

Hi Alex,

A TreeGrid sample was added to GitHub Wisej-Examples repository. Besides the data bound data table example, there is also an unbound example that uses POC objects.

  • You must to post comments
0
0

Hi Luca,

Ok, I have to admit I hadn’t thought about deeper hierarchy levels. I.e. I only considered one “expand” button on the top parent row header and no more on its child rows. I suppose what I really have in mind is more a master (parent) – detail (children) situation and not a real multi-level hierarchy. That’s why I tend to believe that the “row control” will be the best in my case.

I will have to play with the sorting as you describe it. For the moment, I have just disabled column header sorting altogether to avoid the problem!

Best,

Alex

 

  • You must to post comments
0
0

Hi Alex,

Putting the open/close button in the row header is possible (it’s like that for the first level in the PropertyGrid control), but it cannot show the hierarchy, all the open/close buttons would be at the same level. It could be an optional property. I haven’t seen tree grids doing that. See Sencha for example: http://examples.sencha.com/extjs/6.5.1/examples/classic/tree/locking-treegrid.html

You’ll also notice that when you see samples from DevEx, Telerik, Sencha, etc they never mix parent and non parent rows. The tree rows as implements in Wisej are quite flexible, but if you mix parent and non parents that’s what’s displayed.

Hierarchical row sorting is done by following the hierarchy. Wisej first create a tree in memory, then sorts it according to the path to the node, then flattens the list and updates the grid. I wasn’t able to break it with the latest build.

Putting an expandable panel under a row can also be a new enhancement. The main problem to adding that to our grid is the virtual scrolling mixed with variable height rows based on rows and not pixels – so a large panel would scroll as one unit. We don’t a solution to this yet since the rows can all be of a different height and with the virtual scrolling we need to be able to jump to a specific row according to the scrollbar position. Still working on this…

Last, but not least 🙂 the DGV in Wisej is extremely integrated with the server at all levels, i.e. data binding, editing, controls in cells, editing controls, events of all sorts, columns  event, scrolling. This makes it a lot more complicated to add super slick client-side features since they’d have to fit into the data and server model. In some cases it may be better to use third party grids and handle the data binding one way, like most js grids do.

Best,

Luca

  • You must to post comments
0
0

Hello again,

  1. Wouldn’t  it be better if the “expand/collapse” icon showed up in the row header instead of the left side of the first cell in the row? The way it is now, the whole picture gives the impression of a false hierarchical relation between the expanded row, the row just above it and its actual “children”, e.g. in your example it looks like row 8 is child of row 7 (false) and 9, 10, 11, … children of row 8 (correct).
  2. As I suspected, when I click on column headers to sort rows, the dgv at some point blows up complaining about parent rows being under a child. It is not easy to handle each column re-ordering separately and re-fill the grid with the right sorting.
  3. I tend to think that the best solution would be a Control property for the DataGridViewRow object, as there is one for the DataGridViewCell object. At the expand event it could be visible, and hidden at collapse. There it would be possible to show another DGV, not necessarily with the same columns as the parent dgv, or a completely different control, either replacing the parent row or shown in parallel with it. Is this possible?

Best,

Alex

 

  • You must to post comments
1
0

Thanks, Frank!

I’ll have a look at your sample tomorrow, but I suppose the sorting will do the trick. Now I don’t know what will happen if the user tries to reorder the grid by clicking on column headers….

And don’t worry about point 3… It turns out that my column was too narrow, and as you push the values of the children rows to the right for indentation, they were pushed beyond the column right edge and they were invisible…

Best,
Alex

  • You must to post comments
1
0

Hi Alex,

I have put together a (simple) sample, that for sure does not reflect the complexity of your real application.
But maybe it gives you the right pointers.

therapy

I have simplified the data into a single DataTable. When populating the grid you need to make sure (by sorting) that you have the correct sequence between parents and children. That way you avoid errors like you have mentioned in point 2.
I can´t reproduce Point 3 as you can see in my screenshot. Maybe you can share more details ?

Sample is attached.

Hope that helps.

Best regards
Frank

 

  • You must to post comments
Showing 6 results
Your Answer

Please first to submit.