How to add a whole box devexpress

First, drag a checkbox control. To maintain the same style, of course, is to drag devexpress checkbox in gridview header box column it as the whole box and the box column of gridview maximum width and a minimum width is set to 20. This eliminates the step of drawing the whole box, and finally a reminder, do not need to do any settings checkbox column. Select the check box step is to add value and function of the following code.

The first step is simple but the most important is to give gridview bound to a data source plus a custom gridview it is you will find a check box column automatically becomes a box

DataTable dt = GetDataSource();
dt.Columns.Add("check", System.Type.GetType("System.Boolean"));
gridControl1.DataSource = dt;
The second step, in the event checkbox control loop assigned to the checkbox column in gridview. This achieves the Select All or Select None function

private void checkEdit1_CheckedChanged(object sender, EventArgs e)
        {
            for (int i = 0; i < gridView1.RowCount; i++)   //循环gridView1的行
            {
                gridView1.GetDataRow(i)["check"] = (Boolean)checkEdit1.EditValue;   //将选复选框列的值和全选框的值统一
            }
        }
The third step, box takes the value of the selected row

private void GetCheck()
        {
            string value = "";   //变量,存储行的选中值
            string strSelected = "";   //想要的结果。可以为任意的类型
            for (int i = 0; i < gridView1.RowCount; i++)    //循环gridView1值
            {
                value = gridView1.GetDataRow(i)["check"].ToString();    //将行的结果复制给变量
                if (value == "True")    //判断,如果行为
                {
                    strSelected += gridView1.GetRowCellValue(i, "week");
                }
            }
            MessageBox.Show(strSelected);
        }




Reproduced in: https: //my.oschina.net/dongri/blog/610916

Guess you like

Origin blog.csdn.net/weixin_34310785/article/details/91765858