This sample displays an ordered, flat data source as a tree. Here, a "flat" data source indicates that all rows in the data source will contain the same column and "ordered" implies that no row can be a child of a row with a higher row number. Every row has an indentation value associated with it. Only rows below the given row, having higher indentation values, are considered sub-nodes in the tree for a given row. The first row following the given row, having an indentation value equal to or less than the given rows, will not be treated as a sub-node.
The implementation uses a CollapsibleDataSource class. This class has an array object that holds an array of sample data objects (think of each of these objects as a row in the underlying grid). Each sample data object has an IndentValue property, an ExpandState property, and an Items string array that holds the different column values for the row. If you want to use a virtual tree grid to hold your data, you will have to modify this sample data class to use your data instead of the generic data that is provided.
Features
QueryCellInfo, QueryColCount, and QueryRowCount are events to be handled in order to implement a virtual grid.
They provide the basic information about the number of rows and columns, and the values of data.
Data from the data source is set using the QueryCellInfo handler.
A tree cell is a custom cell type and GridStaticCellModel is inherited to create this cell type.
The Model class handles the serialization requirements for the control and creates the Renderer class. The renderer class handles the UI requirements of the cell, such as drawing and handling mouse actions.
Context menu for column 1 and events are described in the custom CellType
Using the ImageIndex property, the images of +/- buttons are chosen.
Each cell is positively and negatively indented by increasing and decreasing the Tag property, which is taken to the OnDraw override as the drawing point.
QueryColCount and QueryRowCount are events used to return the column and row count that are in demand.
The SaveCellInfo event is used to store data back into the data source when data is changed or modified.
QueryRowHeight and QueryColWidth handlers are used to set the size of a row or column (optional).
The virtual grid is refreshed by calling ResetVolatileData, and all other events described above are triggered for this call.
This sample also illustrates serialization in binary format.