Delphi Cxgrid Gets the selected column, collation, value in the cell currently being edited cxGrid1DBTableView1.Controller.FocusedRowIndex the current line number
4. Get Cxgrid Collation
CxGrid1DBTableView1.Controller.FocusedRow as a forward
CxGrid1DBTableView1.Controller.FocusedColumn Current Column
CxGrid1DBTableView1.Controller.FocusedColumnIndex Current column number
CxGrid1DBTableView1.Controller.EditingItem the cell box in the current edit
CxGrid1DBTableView1.Controller.EditingController.Edit The current edit box
You can take the value of the current cell in the edit state:
If CxGrid1DBTableView1.Controller.FocusedColumn.Editing Then
ShowMessage (CxGrid1DBTableView1.Controller.EditingController.Edit. Editingvalue)
Else
CxGrid1DBTableView1.DataController.GetValue (CxGrid1DBTableView1.DataController.FocusedRecordIndex,
CxGrid1DBTableView1.Controller.FocusedItemIndex);
The values in the cell can be obtained in a non-editable state:
Oncellclick Event code:
Procedure Tform1.cxgrid1dbtableview1cellclick (
Sender:tcxcustomgridtableview;
Acellviewinfo:tcxgridtabledatacellviewinfo; Abutton:tmousebutton;
Ashift:tshiftstate; var ahandled:boolean);
Var
V:variant;
Begin
V: = Acellviewinfo.value;
End
Fetch column Value
I: = CxGrid1DBBandedTableView1.Controller.FocusedColumn.Index;
CxGrid1DBBandedTableView1.DataController.GetValue (Cxgrid1dbbandedtableview1.controller.selectedrows[0]. Recordindex,i);
cxgrid1dbtableview1.datacontroller.values[row, column]
Gets the focus
Cxgrid1dbtableview1.columns[5]. Focuswithselection;
Cxgrid1dbtableview1.columns[4]. Focused:=true;
Get the value of the cell that is currently clicked
Uses clipbrd;
Oncellclick Event code:
Procedure Tform1.cxgrid1dbtableview1cellclick (
Sender:tcxcustomgridtableview;
Acellviewinfo:tcxgridtabledatacellviewinfo; Abutton:tmousebutton;
Ashift:tshiftstate; var ahandled:boolean);
Var
V:variant;
Begin
V: = acellviewinfo.value;//value
Clipboard.astext: = Vartostr (v);//Save to Clipboard
End
The name of the Cxgrid Dbtableview is DGTV1
1. Return the selected number of rows GDTV1. Datacontroller.getselectedcount;
2. Returns the index of the selected row: GDTV1. Datacontroller.getselectedrowindex (0), which represents the index of the first selected row
3. Return the data of the selected row;
Var
I, J:integer;
Begin
For I:=0 to GDTV1. Datacontroller.getselectedcount-1 DO begin
J: = GDTV1. Datacontroller.getselectedrowindex (I);
ShowMessage (Vartostr (GDTV1. Datacontroller.getvalue (J, 0)); Select the value of the column in row
End
End
Const
Orderarray:array[sonone. Sodescending] of String = (' None ', ' ASC ', ' DESC ');
Var
I:integer;
S, orderstr:string;
Begin
For I: = 0 to GDTV1. SortedItemCount-1 DO begin
If S <> ' then
S: = s + ', ';
ORDERSTR: = Orderstr + GDTV1. Sorteditems[i]. Databinding.defaultcaption + ";
ORDERSTR: = Orderstr + Orderarray[tcxdatasortorder (GDTV1. Sorteditems[i]. SortOrder)];
S: = s + orderstr;
End
ShowMessage (' ORDER by ' + S);
5. Get the values for multiple selections
For I: = 0 to Cxgrid1. Selectedrows.count-1 do
Begin
Cxgrid1. DataSource.DataSet.GotoBookmark (Pointer (cxgrid1. Selectedrows.items[i])); Locate the selected field
End
6.//Select the value of the 1th column of the row
For i:=0 to Cxgrid1dbtableview1.datacontroller.getselectedcount-1 do
Begin
J: = CxGrid1DBTableView1.DataController.GetSelectedRowIndex (I);
ShowMessage (Vartostr (CxGrid1DBTableView1.DataController.GetValue (J, 0));
End
7. Get the value of the selected row
With Cxgrid1dbtableview1.controller do
Begin
For i:=0 to SelectedRowCount-1 do
Begin
Selectedrows[i]. Focused:=true;
ShowMessage (Adoquery1.fieldbyname (' MC '). asstring);
End
End
Cxgrid usage (take row, column value; Locate selected row, etc.)