DevExpress GridControl使用教程:之 添加 checkbox 復選框


 

 

 

添加一列,FieldName為"FLAG",將ColumnEdit設置為復選框樣式

gridview1   =》optionsbehavior =》  editable設置為true   (如果自己定義全選,取消全選此處可以設置false)

將要綁定的DataTable添加列"FLAG",Type為bool

gridview1   =》columnEdit => new =》checkEdit 

此時就會出現復選框 但是 復選框 無法選擇 需要繼續 給 gridView 添加

點擊事件  RowCellClick

private void gv_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e)
{
int index = this.gv.FocusedRowHandle;
selStudent = gv.GetRow(index) as StudentDTO;
if (selStudent == null)
{
FrmAlert.ShowMessageBoxErrorDialog(this, "請選中一行!");
return;
}
if (e.Column.Tag.ToSafeString() == "checkbox")
{
int selectIndex = this.gv.FocusedRowHandle;
StudentDTO row = this.gv.GetRow(selectIndex) as StudentDTO;
if (row != null)
{
DevExpress.Data.CustomSummaryEventArgs e1 = new DevExpress.Data.CustomSummaryEventArgs();
row.Flag = !row.Flag;
}
this.gv.RefreshData();
}
}

獲取:

string value = gridview.GetDataRow(i)["FLAG"].toString();

value == "true" ||  "" ("false")

設置為多選

gridView1 .OptionsSelection.MultiSelect = true;

gridView1 .OptionsSelection.MultiSelectMode = DevExpress.XtraGrid.Views.Grid.GridMultiSelectMode.RowSelect;

 

代碼如下 :

 注意:Tag 顯示在下圖

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM