Description:1. IMPORTANT. This feature requires the Data Controller to be in the following settings:
I would like to add a Check column to my View to allow users to select records. I do not need to store the values of this column in the underlying table and thus, I do not want to add an extra field to the table's structure. Does your Grid allow such a column?
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):
- default data loading mode - make sure to set the Data Controller's DataModeController.GridMode property to False
<aView>.DataController.DataModeController.GridMode := False;
- Smart Refresh mode - set the Data Controller's DataModeController.SmartRefresh property to True[Delphi]
<aView>.DataController.DataModeController.SmartRefresh := True;
- key field(s) - you must initialize the Data Controller's KeyFieldNames property
2. Add a new column to a View. Do not initialize its DataBinding.FieldName property.[Delphi]
<aView>.DataController.KeyFieldNames := 'aUniqueField';
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]
var aCol: TcxGridDBColumn; ... aCol := <aView>.CreateColumn; with aCol do begin Name := 'colUnbound'; Caption := 'Check'; end;
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]
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]
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.
How to implement unbound checkboxes in a bound View
How to display an image from a data table in an Unbound View
How to show a row number value in an unbound Grid column
How to set an item's Properties at runtime
Show all comments