Adding selection columns to Cxgrid
1, in the dataset (Query/table/clientdataset etc) Fieldeditor increase the calculated field Fdselect,datatype is a string, of course, other types can be. Fieldkind is set to fkcalculated or Fkinternalcalc; When set to Fkinternalcalc, it should be noted that the SELECT statement reads as follows: Select ' 0 ' as fdselect,* from TableA, Otherwise, the field "* * *" not found will be reported. When set to fkcalculated, you do not need to change the original statement.
Object Strngfldwaitinfdselect:tstringfield
Fieldkind = Fkinternalcalc
FieldName = ' Fdselect '
End
2, Cxgrid dbtableview Add Column Cxgrdbclmnselect, set the properties as a checkbox, the following settings:
Object Cxgrdbclmnselect:tcxgriddbcolumn
Caption = #36873 #25321
databinding.fieldname = ' fdselect '
propertiesclassname = ' tcxcheckboxproperties '
properties.displaygrayed = ' nssunchecked '
properties.valuechecked = ' 1 '
properties.valuegrayed = ' nssunchecked '
properties.valueunchecked = ' 0 '
MinWidth = 25
options.editing = false //Important, many friends talked about, not responding to Cellclick events, Set to False to respond.
options.filtering = False
Options.incsearch = False
end
3. Add code in Cellclick or MouseUp as needed
Var
Row:integer;
Begin
If CxgrdbtblvwGrid1DBTableView1.ViewData.RecordCount = 0 Then
Exit;
row: = CxgrdbtblvwGrid1DBTableView1.DataController.FocusedRowIndex;
If Cxgrdbtblvwgrid1dbtableview1.viewdata.records[row]. Values[0] = ' 1 ' Then
Cxgrdbtblvwgrid1dbtableview1.viewdata.records[row]. Values[0]: = ' 0 '
Else
Cxgrdbtblvwgrid1dbtableview1.viewdata.records[row]. Values[0]: = ' 1 ';
End
4, F9 look at the effect.
Ps:fkcalculated and Fkinternalcalc
Fields calculated by SQL servers or the Borland Database Engine to display the results of a query that returns a live data Set has a fieldkind of Fkinternalcalc, not fkcalculated. This was because the field values are stored in the dataset. Calculated fields in a client datasets that is calculated in an event handler but stored in the dataset also has a Fi Eldkind of Fkinternalcalc instead of fkcalculated. Unlike regular calculated, internally calculated fields can is used in filter expressions. They can is edited, but the changes is discarded. To prevent editing, set the property to True.
Summary of Cxgrid's checkbox