Developer

Migrate from ListView

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

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

Part 1 - Designer


The first part is mostly a matter of dropping a NextGrid onto a form containing the ListView to convert and set the ListViewConverter property of the NextGrid to the ListView to convert.


NextGrid will automatically create columns matching the ListView using a nxTextColumn for each ListViewColumn. After conversion the property is cleared (as conversion normally is performed only once).

So a ListView looking like:

will be recreated by NextGrid as:

Basic column properties like the Text and Width are transferred during the conversion.

As ListView has only textual columns and NextGrid typed columns (like nxTextColumn and nxNumberColumn), a more optimal conversion that uses the advantages of NextGrid can be done only manually as there is no information to determine the type of the NextGrid column to be used.

Part 2 - Coding


The main difference between ListView and NextGrid is that each cell in NextGrid is an Object that can be accessed through the nxGridCell value property. Also events and methods are different as ListView is just a flat list of items where NextGrid uses a tree for all it's data even when it is just displaying a flat list.

Adding Rows


The basic method for adding a row is calling:

nextGrid1.AddRow();
which just appends a single row to the NextGrid.
Optionally the number of rows to add can be specified like:

nextGrid1.AddRow(10000);
which adds ten thousand empty rows to the grid.

Adding Cell Data


The easiest way to add cell data to a NextGrid is during adding of a row. As AddRow() returns the newly added nxGridRow one can simply use its Fill method like

nextGrid1.AddRow().Fill("CELL DATA");
or

nextGrid1.AddRow().Fill("A1", "B1", "C1");
As Cells contain objects in NextGrid, parameters of the Fill() methods are off-course not limited to Strings but can be all kind of Objects as long as they match the column type. For nxTextColumn the ToString() method of the Object is used to render the cell content. For Number columns it has off-course to be a numerical type.

In NextGrid rows and cells can be addressed as an array like nextgrid1[0]for accessing a nxGridRow.
As NextGrid uses a more complex data structure, it uses the AbsoluteIndex property of a nxGridRow for addressing individual rows.

Please note that it's not possible to simply increment the AbsoluteIndex to address a next row.

So if one adds a row using AddRow(), its AbsoluteIndex property can be used to address the nxGridCell using the NextGrid like:

Int32 rowndx = nextGrid1.AddRow().AbsoluteIndex; nextGrid1[rowndx][colndx].Value = 10;
Alternatively one can use two dimensional addressing like:

Int32 rowndx = nextGrid1.AddRow().AbsoluteIndex; nextGrid1[colndx, rowndx].Value = 12;
Note that here addressing is done with [x,y]style coordinates.

A last method is using the nxGridRow like:

nxGridRow gr = nextGrid1.AddRow(); gr[colndx].Value = 14;

See also