Home - Forums-.NET - FlyGrid.Net (Windows Forms) - Refresh causes tree grid to collapse nodes

FlyGrid.Net (Windows Forms)

.NET Datagrid - Fast, highly customizable, industry standards .NET data grid control for WinForms

This forum related to following products: FlyGrid.Net

Refresh causes tree grid to collapse nodes
Link Posted: 05-Sep-2006 04:49
Hi,

I am using FlyGrid version 1.4.0.22 and have a tree grid in virtual mode. On indent/outdent, to refresh the count, I am using the following code:

Flygrid.Rows.Reset()
Flygrid.Rows.RootNode = Nothing

Setting the RootNode to nothing, collapses all the nodes. I did a search and have referred to a similar problem posted here http://www.9rays.net/forums/viewtopic.php?t=839 and also did a search for “collapse”, but did not find any solution for this.

Thanks,
Hardik
Link Posted: 05-Sep-2006 09:08
Yes, in this case rows is rebuilds nodes.
You can store 'expanded state in the node's data to to restore expandedstate of node when rows requests nodes in virtual mode.
Link Posted: 05-Sep-2006 09:42
Looks like setting the RootNode to Nothing might not be the right solution for my scenario then, as it refreshes the entire grid. I think all I need to refresh here is the new Parent and the old Parent on indent/outdent. But which methods should I call to refresh specifc rows and update their count?

Your solution for saving the expanded state might still be useful in other cases where I might have to refresh the entire grid.

Thanks,
Hardik
Link Posted: 05-Sep-2006 11:00
You can copy existng nodes before Rows.Reset to provide exisitng nodes when Rows will refresh nodes and create new node when it is necessary.
But if you sort nodes this way will not a good, as new node can be sorted.
Link Posted: 05-Sep-2006 11:21
Are you suggesting to use a copy of existing nodes to preserve the expanded state of the \"untouched\" nodes, and recreate new ones for the ones that I need refreshed?

It will be a very inefficient process to do Rows.Reset and rebuild the entire grid when I just need one particular row and its children refreshed. Is there no way that I can just reset or refresh or recreate a particular row?

Thanks,
Hardik
Link Posted: 05-Sep-2006 13:15
Are you suggesting to use a copy of existing nodes to preserve the expanded state of the \"untouched\" nodes, and recreate new ones for the ones that I need refreshed?

You can create array of nodes as external source of nodes that provided them in virtual mode. In this case it is not necessary to copy nodes before refreshing.
But more optimal - store expand state of node in the external store and restore state in VirtualMode_InitNewnode.
Link Posted: 05-Sep-2006 19:22
Can you please also reply to my other question of refreshing just one row? I would rather do that than rebuild the entire grid on an indent. It makes more sense and is obviously more efficient to recreate just the affected nodes (i.e. the new parent, and the old parent). Is there a way to do that?

Thanks,
Hardik
Link Posted: 06-Sep-2006 12:07
To refresh just one row you can use FlyGrid.InvalidateNode method, multiple rows or single row - FlyGrid.InvalidateRows method.
Link Posted: 06-Sep-2006 12:43
From what I understand, Invalidate method is used to let the control's (in this case grid's) Paint event know which specific area to redraw. So, yes,  I might need to use that, however, before calling the Invalidate method, I still need to recreate the affected nodes, as the node I indented, now has a new parent.
So I need to somehow call the VirtualMode_InitNewNode method, or its equivalent, to recreate just the affected nodes, and set them up in the NodeBase collection of the grid. How do I go about doing that?

Thanks,
Hardik
Link Posted: 08-Sep-2006 07:26
You can use your own VirtualNode implementation to access to protected OnChange method to invalidate or refresh some node.
But - in virtual mode nodes doesn't store values, nodes fetch data for their cells via VirtualMode_GetValue event, so you shouldn't 'refresh' some node, you can invalidate node to refresh displayed data.