GridControl中新增checkbox複選框
阿新 • • 發佈:2019-02-16
新增一列,FieldName為 "check",將ColumnEdit 設定為 複選框 樣式。gridview1 editable設定為true
將要繫結的DataTable新增列 "check",Type 為 bool。
繫結DataTable到GridControl。
獲取: string value = gridview.GetDataRow(i)["check"].toString();
value == "true" || "" ("false")
設定為多選
gridView1 .OptionsSelection.MultiSelect
= true;
gridView1 .OptionsSelection.MultiSelectMode = DevExpress.XtraGrid.Views.Grid.GridMultiSelectMode.RowSelect;
測試的例子如下:
給gridcontrol新增資料
string strConn = "###"; OracleConnection oconn = new OracleConnection(strConn); string strComm = "select CITY_NAME,DISTRICT_NAME from CC_COMPLAINT_POINT"; OracleDataAdapter oda = new OracleDataAdapter(strComm, oconn); DataSet ds = new DataSet(); try { oda.Fill(ds, "cx"); ds.Tables["cx"].Columns.Add("check",System.Type.GetType("System.Boolean")); gridControl1.DataSource = ds.Tables["cx"]; //Rel.DataSource = ds.Tables["cx"]; //Rel.DisplayMember = "DISTRICT_NAME"; //Rel.ValueMember = "CITY_NAME"; } catch(Exception ex) { MessageBox.Show(ex.ToString()); } finally { oconn.Close(); }
點選測試check按鈕響應如下事件(獲取被check的資料)
private void buttonX3_Click(object sender, EventArgs e) { string value=""; string strSelected=""; for (int i = 0; i < gridView1.RowCount; i++) { value = gridView1.GetDataRow(i)["check"].ToString(); if (value == "True") { strSelected += gridView1.GetRowCellValue(i, "DISTRICT_NAME"); } } MessageBox.Show(strSelected); }