//1cxgrid動態建立列
procedure TFrmRuleEdit.CreateCols;
var
Column: TcxGridDBColumn;
begin
cdsPowerPrj.First;
while not cdsPowerPrj.Eof do
begin
Column := viewPower.CreateColumn;
Column.Caption := cdsPowerPrj.FieldByName('description').Text;
Column.DataBinding.FieldName := cdsPowerPrj.FieldByName('powerName').Text;
Column.PropertiesClassName := 'TcxCheckBoxProperties';
Column.Width := 50;
cdsPowerPrj.Next;
end;
end;
//2cxGrid 透過欄位名取得列
Column := cxGrdPayOrdVwd.GetColumnByFieldName(FieldName);
//3cxGrid動態建立的列裡動態建立事件的方法
procedure TForm1.cxButton1Click(Sender: TObject);
begin
//設定第3列為按鈕屬性:
cxGrid1DBTableView1.Columns[3].PropertiesClass:=TcxButtonEditProperties;
//關聯點選事件:
(cxGrid1DBTableView1.Columns[3].Properties as TcxButtonEditProperties).OnButtonClick
:=cxGrid1DBTableView1ColumnPropertiesButtonClick;
end;
轉自https://www.cnblogs.com/Thenext/p/14062263.html