Unbound Mode
- 3 minutes to read
This topic explains how to setup your grid control to work in unbound mode. Unbound mode is a data loading mode in which the grid control does not use any data source. In this mode, the cache of the View’s data controller is manually populated with values. Refer to the Unbound Mode: Master-Detail topic for information on how to create master-detail relationships in unbound mode.
Let’s explore an example from the UnboundSimple demo. In this demo, a grid control is populated in unbound mode with data relating to the solar system.
Creating and Initializing Columns
Columns within a grid View can be created at design or runtime. To create columns at design time, use the Component Editor. You can refer to the Create And Delete Columns topic for details.
If a grid View is not connected to a data source, columns should be created manually. Additionally, you need to set the appropriate data type for each column. Use the DataBinding.ValueType or DataBinding.ValueTypeClass property for this purpose. See the TcxValueType class topic for available types. The following code shows how to specify the value type for four columns of the tvPlanets View.
tvPlanetsPERIOD.DataBinding.ValueTypeClass := TcxFloatValueType;
tvPlanetsDISTANCE.DataBinding.ValueTypeClass := TcxIntegerValueType;
tvPlanetsNAME.DataBinding.ValueTypeClass := TcxStringValueType;
tvPlanetsORBITS.DataBinding.ValueTypeClass := TcxStringValueType;
Loading Data
Before loading data, you need to provide the number of records available to your grid View. To display two records within the tvPlanets View, write the following:
The Values property of the data controller allows you to get/set values of a particular record. It requires two indexes to be supplied: the record index and the item (column) index. Below two records are filled with values. The following code shows how to enter data into the four columns mentioned above:
var
APeriodIndex, ADistanceIndex, AOrbitsIndex, ANameIndex: Integer;
//...
//Indexes to access values in particular columns
APeriodIndex := tvPlanetsPERIOD.Index;
ADistanceIndex := tvPlanetsDISTANCE.Index;
ANameIndex := tvPlanetsNAME.Index;
AOrbitsIndex := tvPlanetsORBITS.Index;
with tvPlanets.DataController do
begin
BeginUpdate;
try
//the first record
Values[0, APeriodIndex] := 87.97;
Values[0, ADistanceIndex] := 57910;
Values[0, ANameIndex] := 'Mercury';
Values[0, AOrbitsIndex] := 'Sun';
//the second record
Values[1, APeriodIndex] := 365.26;
Values[1, ADistanceIndex] := 149600;
Values[1, ANameIndex] := 'Earth';
Values[1, AOrbitsIndex] := 'Sun';
finally
EndUpdate;
end;
end;
When executing this code, the grid View will only display two records as follows:
At design time, you can use the Layout and Data Editor window to enter data directly into a non data-aware View. Refer to the Data Editing topic to learn more.