Delphi cxgrid usage
1. Bind data
Method
Cxgrid1dbtableview1. datacontroller. datasource: = performance1
2. Remove "drag a column header here to group by that column"
Method
Cxgrid1dbtableview1. optionsview. Set groupbybox to false.
3. Remove the lower triangle data from the header.
Method
Cxgrid1dbtableview1. optionscustomize. columnfiltering is set to false
4. Add serial number
Method
Add the mycount field type to dataset as string
Add the display field number mycount in cxgrid.
Write event for this field
Procedure tfrm_form.redataset2mycountgettext (Sender: tfield;
VaR text: string; displaytext: Boolean );
Begin
Inherited;
Text: = inttostr (redataset2.recno );
End;
Bind the serial number to the field mycount
5. Add a column to the cxgrid to display the checkbox.
Method
Add the myselect field type as Boolean in dataset.
Add a display field in cxgrid and select
Set the properties of the select field to checkbox. readonly = false;
Nullstyle = nssunchecked
Procedure tfrm_form.cxgrid1dbtableview1cellclick (
Sender: tcxcustomgridtableview;
Acellviewinfo: tcxgridtabledatacellviewinfo; abutton: tmousebutton;
Ashift: tshiftstate; var ahandled: Boolean );
VaR
Row: integer;
Begin
Inherited;
If acellviewinfo. item. Name = 'mycheck' then
Begin
Row: = cxgrid1dbtableview1. datacontroller. focusedrecordindex;
If cxgrid1dbtableview1. viewdata. Records [row]. Values [0] = true then
Cxgrid1dbtableview1. viewdata. Records [row]. Values [0]: = false
Else
Cxgrid1dbtableview1. viewdata. Records [row]. Values [0]: = true;
End;
End;
Procedure tfrm_form.cxgrid1dbtableview1mouseup (Sender: tobject;
Button: tmousebutton; shift: tshiftstate; X, Y: integer );
VaR
Row: integer;
Begin
Inherited;
// Single answer
// For row: = 0 to cxgrid1db tableview1. datacontroller. RecordCount-1 do
// Begin
// Cxgrid1dbtableview1. viewdata. Records [row]. Values [0]: = false;
// End;
// Select multiple
If cxgrid1dbtableview1. datacontroller. recordcount <> 0 then
Begin
Row: = cxgrid1dbtableview1. datacontroller. focusedrecordindex;
If cxgrid1dbtableview1. viewdata. Records [row]. Values [0] = true then
Cxgrid1dbtableview1. viewdata. Records [row]. Values [0]: = false
Else
Cxgrid1dbtableview1. viewdata. Records [row]. Values [0]: = true;
End;
End;
This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/fkedwgwy/archive/2009/08/19/4463732.aspx