gridcontrol中添加checkbox复选框

来源:互联网 发布:数据库关系模型示例 编辑:程序博客网 时间:2024/04/18 13:15

添加一列,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添加数据

[c-sharp] view plaincopy
  1. string strConn = "###";  
  2.             OracleConnection oconn = new OracleConnection(strConn);  
  3.             string strComm = "select CITY_NAME,DISTRICT_NAME from CC_COMPLAINT_POINT";  
  4.             OracleDataAdapter oda = new OracleDataAdapter(strComm, oconn);  
  5.             DataSet ds = new DataSet();  
  6.             try  
  7.             {  
  8.                 oda.Fill(ds, "cx");  
  9.                 ds.Tables["cx"].Columns.Add("check",System.Type.GetType("System.Boolean"));  
  10.   
  11.                 gridControl1.DataSource = ds.Tables["cx"];  
  12.                 //Rel.DataSource = ds.Tables["cx"];  
  13.                 //Rel.DisplayMember = "DISTRICT_NAME";  
  14.                 //Rel.ValueMember = "CITY_NAME";  
  15.                   
  16.             }  
  17.             catch(Exception ex)  
  18.             {  
  19.                 MessageBox.Show(ex.ToString());  
  20.   
  21.             }  
  22.             finally  
  23.             {  
  24.                 oconn.Close();  
  25.    
  26.             }  

点击测试check按钮响应如下事件(获取被check的数据)

[c-sharp] view plaincopy
  1. private void buttonX3_Click(object sender, EventArgs e)  
  2.         {  
  3.             string value="";  
  4.             string strSelected="";  
  5.             for (int i = 0; i < gridView1.RowCount; i++)  
  6.             {  
  7.                 value = gridView1.GetDataRow(i)["check"].ToString();  
  8.                 if (value == "True")  
  9.                 {  
  10.                     strSelected += gridView1.GetRowCellValue(i, "DISTRICT_NAME");  
  11.    
  12.                 }  
  13.             }  
  14.             MessageBox.Show(strSelected);  
  15.         }  

运行结果如下:


在此谢谢:http://blog.csdn.net/weinierbian/article/details/6255402

0 0
原创粉丝点击