FlexGrid for WinForms
Storing and Retrieving Data
Show AllShow All
Hide AllHide All

The C1FlexGrid control can be used in bound or unbound mode. In bound mode, the grid is connected to a data source, and all the data displayed on the grid comes from the data source. In this mode, changing data on the grid changes it in the underlying data source. In unbound mode, the grid manages its own data source.

In either bound or unbound modes, the easiest way to access data in the C1FlexGrid is using the Row and Column indexers. The indexers allow you to specify a cell in a row or column from which to get or set the data stored there. For example, the following code selects the data in the second cell of a row:

To write code in Visual Basic

To write code in C#

The Item property is another easy way to access data in the C1FlexGrid. The Item property is an indexer that takes row and column indices and gets or sets the data stored in the cell. (You can also use column names as indices.) For example, the following code stores row numbers in the first grid column:

To write code in Visual Basic

To write code in C#

When you assign a value to a cell, the grid tries to convert that value into the column's specified DataType. If the conversion fails, the grid fires the GridError event and does not change the cell. You can override this behavior using the SetData method and setting the coerce parameter to False.

When you retrieve data using the indexers, the grid returns the actual data stored in the cell. To retrieve a string containing the formatted version of the data (what the grid displays to the user), use the GetDataDisplay method.

You can also set and retrieve the contents of the selection using the Clip property. This property is especially useful in handling the clipboard and drag-drop operations. By default, the Clip property returns a string with tab characters (Chr(9)) between cells and return characters (Chr(13)) between rows. To use different delimiters, change the ClipSeparators property.

Finally, you can set and retrieve the contents of arbitrary cell ranges using CellRange objects.

See Also

 

 


Copyright © GrapeCity, inc. All rights reserved.

Product Support Forum |  Documentation Feedback