Developer

Migrate from TreeView

Migrating from a .NET TreeView to using NextGrid consists of two parts.

The first thing to do is to replace TreeView by a NextGrid in the Visual Studio Designer. The second part is off-course making the code work as the .NET TreeView and NextGrid share a lot but still work differently.

Part 1 - Designer


The first part is a matter of dropping a NextGrid onto a form containing the TreeView to convert. Then add a single nxTreeColumn using the NextGrid Column Editor ad adjust it's properties.


NextGrid will automatically create a single nxTreeColumn matching the TreeView. After conversion the property is cleared (as conversion normally is performed only once).

So a TreeView looking like:

will be recreated by NextGrid as:

Part 2 - Coding


NextGrid natively uses a Tree as underlying data structure. When empty the tree (which can be accessed through the nextGrid1.Data property) contains a single (hidden) top-level node called Root. Every node in the tree has a Root property that returns this top level node. The Root has an AbsoluteIndex property value of zero.

The treelike structure is shown only when a nxTreeColumn is present (and unlike a TreeView it does not have to be the only nor first column).

Adding toplevel Nodes

To add a top-level row to the grid, either:

nextGrid3.AddChildRow(0)[0].Value = "TOPNODE";or

nextGrid3.AddRow()[0].Value = "TOPNODE";

Adding child Nodes

For adding children to a nxGridRow its AbsoluteIndex property is used like

Int32 ndx = nextGrid3.AddRow()[0].Fill("PARENT"); nextGrid3.AddChild(ndx).Fill("CHILD");

Mixing Trees and Grids

Adding more columns to the NextGrid is possible. Enumerating children of a node can be done by using the Children property of a nxGridRow. This will return a object from the underlying data structure of which the Payload property contains a nxGridCells object that can be used to address individual cells.

It might seem a bit complex but NextGrid uses a Tree Data Structure that contains nxGridCells Payload in each of its tree nodes. The Tree Data Structure itself does not know what kind of data its actually storing. It also uses a special index to speed up the tree so that it's almost as fast as a flat array for accessing data.

Note that using the property Root or it's AbsoluteIndex (which is an internal property of the underlying tree structure) will result in errors when building the tree.



See also