zoukankan      html  css  js  c++  java
  • 使用DX写系统的随手笔记

    设置gridcontrol.gridview为只读的方法

    gridview属性中OptionsBehavior属性editable,readonly

    设置gridcontrol.gridview列为只读

    GridView.Columns[i].OptionsColumn.AllowEdit=false;

    gridcontrol中添加checkbox复选框

    分类: winForm桌面程序开发 567人阅读 评论(0) 收藏 举报
     

    添加一列,FieldName为 "check",将ColumnEdit 设置为 复选框 样式。

      将要绑定的DataTable添加列 "check",Type 为 bool。 必须要设置为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添加数据

    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.             }  
    1. 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的数据)

    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.         }  
    1. 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);        }  

    运行结果如下:

  • 相关阅读:
    [转载]浅谈多态机制的意义及实现
    [转载]浅析Java虚拟机结构与机制
    为什么调用 FragmentPagerAdapter.notifyDataSetChanged() 并不能更新其 Fragment?
    Android-- FragmentStatePagerAdapter分页
    android-点击空白或点击除EditText之外的控件隐藏软键盘
    populating-next-right-pointers-in-each-node
    roman-to-integer
    same-tree
    palindrome-number
    best-time-to-buy-and-sell-stock
  • 原文地址:https://www.cnblogs.com/jlfood/p/2372550.html
Copyright © 2011-2022 走看看