Working with a Grid

You can use the AddItem method to insert rows of text in a Grid. AddItem inserts a row into the grid at the current column and row position. You can fill multiple cells with data by using the tab character (vbTab) to separate the data for each cell.

To insert data into existing cells, use the Text, TextMatrix, or Clip methods. The Text method inserts text at the current row and column position, while TextMatrix enables you to specify a different row and column. The Clip method fills the selected range of cells with text. You also can store the contents of a range of cells using the Clip method. When working with text in a Grid, the tab character (vbTab) separates cells, and the carriage return character (vbCr) separates columns. You can change the current position to insert text by changing the Col and Row properties. A change in the current cell position triggers the following order of events: LeaveCell, EnterCell, RowColChange.

When a user chooses a cell other than the selected cell or drags to select a new range of cells, the Grid control initiates the SelChange event. Use the Row, Col, RowSel, or ColSel properties to determine whether the SelChange event will select a cell or a range of cells.

The Grid control includes methods for removing rows. To delete one row, use the RemoveItem method. To delete all rows from a Grid, use the Clear method.

After you have added all the data to a Grid, you can sort the rows by setting the Sort property. The columns defined by the Col and ColSel properties determine which columns are used to sort the Grid. If you set Sort to flexSortCustom, you can create a custom sorting algorithm in your code for the Compare event.

Because the Compare event uses row numbers instead of text values, you can use it to compare any property value for that row, including RowData. The RowData and ColData properties enable you to associate a number with each row or column. RowData is useful because the Index property for a row stores only the current position. After the Grid control rearranges the rows during a sorting operation, the Index property for each row changes to reflect the new row order.