cxGrid設定列為按鈕並設定按鈕事件
阿新 • • 發佈:2020-12-23
因為業務需要展示,在每行的資料最後一列顯示一個按鈕,點選按鈕刪除對應的資料。使用cxGrid能完美實現。
1、設定按鈕列的properties是buttonedit
2、設定properties下的屬性viewStyle=vsButtonsAutoWidth
3、設定Options中的ShowEditButtons=isebAlways
4、點選properties下的buttons按鈕,彈出: 到此介面設定結束,現在我們為這個按鈕新增一個點選事件:
2、設定properties下的屬性viewStyle=vsButtonsAutoWidth
3、設定Options中的ShowEditButtons=isebAlways
4、點選properties下的buttons按鈕,彈出: 到此介面設定結束,現在我們為這個按鈕新增一個點選事件:
- //按鈕事件:
- procedure colButtonPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
- //關聯點選事件:
-
(dbcolAdd.Properties as TcxButtonEditProperties).OnButtonClick
-
:= colButtonPropertiesButtonClick;
示例:
...... private {Privatedeclarations} procedurecxGrid1DBTableView1ColumnPropertiesButtonClick( Sender:TObject;AButtonIndex:Integer); public {Publicdeclarations} end; var Form1:TForm1; implementation {$R*.dfm} procedureTForm1.cxGrid1DBTableView1ColumnPropertiesButtonClick( Sender:TObject;AButtonIndex:Integer); begin //....... end; procedureTForm1.cxButton1Click(Sender:TObject); begin //設定第3列為按鈕屬性: cxGrid1DBTableView1.Columns[3].PropertiesClass:=TcxButtonEditProperties; //關聯點選事件: (cxGrid1DBTableView1.Columns[3].PropertiesasTcxButtonEditProperties).OnButtonClick :=cxGrid1DBTableView1ColumnPropertiesButtonClick; end; ......