Σάββατο 15 Νοεμβρίου 2014

How to set up an unbound item in a data-aware View

The new ExpressQuantumGrid 5 supports this functionality and allows you to set such an unbound column (row - for a Card View).


 Here are the necessary steps (the code snippets will illustrate how to perform the same operations programmatically):
1. IMPORTANT. This feature requires the Data Controller to be in the following settings:
- default data loading mode - make sure to set the Data Controller's DataModeController.GridMode property to False
[Delphi]Open in popup window
<aView>.DataController.DataModeController.GridMode := False;
- Smart Refresh mode - set the Data Controller's DataModeController.SmartRefresh property to True
[Delphi]Open in popup window
<aView>.DataController.DataModeController.SmartRefresh := True;
- key field(s) - you must initialize the Data Controller's KeyFieldNames property
[Delphi]Open in popup window
<aView>.DataController.KeyFieldNames := 'aUniqueField';
2. Add a new column to a View. Do not initialize its DataBinding.FieldName property.
[Delphi]Open in popup window
var aCol: TcxGridDBColumn; ... aCol := <aView>.CreateColumn; with aCol do begin Name := 'colUnbound'; Caption := 'Check'; end;
3. Set the column's DataBinding.ValueType to an appropriate value. This property specifies the string representation of the data type which the data binding provides. For example, if you wish the column to store logical values, set the DataBinding.ValueType property to Boolean.
[Delphi]Open in popup window
uses cxDataStorage; ... aCol.DataBinding.ValueTypeClass := TcxBooleanValueType;
NOTE: When setting the value type programmatically, you should refer to the DataBinding.ValueTypeClass property instead and use the corresponding value type class.
4. Bind an appropriate editor to the column. Set the column's Properties property to the necessary value (CheckBox in our instance).
[Delphi]Open in popup window
uses cxCheckBox; ... aCol.PropertiesClass := TcxCheckBoxProperties; //OR aCol.PropertiesClassName := 'TcxCheckBoxProperties';
NOTE: When setting the Properties property value programmatically, you should refer to the item's PropertiesClass or PropertiesClassName property instead and use the corresponding properties type class.
5. Adjust the column Properties' settings as your need dictate. For example, set the ValueChecked and ValueUnchecked properties to the values used in your application:
[Delphi]Open in popup window
with aCol.Properties as TcxCheckBoxProperties do begin AllowGrayed := False; ValueChecked := True; ValueUnchecked := False; end;
That's all. Now, you can modify the values of the newly added column and refer to them using the standard methods of the ExpressDataController.
Important Note: The described approach is not suitable for unbound columns in the detail view of the Master-detail model because the DataModeController.SmartRefresh property contradicts the detail DataSet refresh procedures.

Δεν υπάρχουν σχόλια:

Δημοσίευση σχολίου