简体   繁体   English

具有DevExpress DataGrid的C#DataSet CheckBox列

[英]C# DataSet CheckBox Column With DevExpress DataGrid

Scenario 情境

I have a DevExpress DataGrid which is bound to a DataSet in C#. 我有一个DevExpress DataGrid,它绑定到C#中的数据集。 I want to populate each dataset row to contain a string in the first column and a checkbox in the second. 我想填充每个数据集行,使其在第一列中包含一个字符串,在第二列中包含一个复选框。 My code below doesn't work quite how I want it to, and I'm not sure why..... 我下面的代码不能完全按照我的要求工作,我不确定为什么.....

The Code 编码

As you can see I've declared a dataset, but when I try and pass in a new checkbox object to the 2nd column it just displays the system name for the checkbox. 如您所见,我已经声明了一个数据集,但是当我尝试将一个新的复选框对象传递给第二列时,它仅显示该复选框的系统名称。

        DataSet prodTypeDS = new Dataset();
        DataTable prodTypeDT = prodTypeDS.Tables.Add();
        prodTypeDT.Columns.Add("MurexID", typeof(string));
        prodTypeDT.Columns.Add("Haganise",typeof(CheckBox));

        //WHY DOES THIS NOT WORK? 
        //(Displays "System.Windows.Forms.CheckBox, CheckState: 0")
        //Instead of a checkbox.
        CheckBox c = new CheckBox();
        prodTypeDS.Tables[0].Rows.Add("Test",c);
        //This doesn't work either....
        prodTypeDS.Tables[0].Rows.Add("Test",c.CheckState);

......I hope this is just because it's a DevExpress datagrid.... ......我希望这仅仅是因为它是一个DevExpress数据网格....

Why do you use a Checkbox column in your DataSet ? 为什么在数据DataSet使用“ Checkbox列?

You should try adding a bool column in your DataSet , when binding the DataSet to the grid, it will automatically use a Checkbox to display the item value. 你应该尝试添加一个bool在列中DataSet ,绑定时, DataSet的网格,它会自动使用复选框以显示项目值。

When you dont have a bool column in your datatable you can also manually/in code set the editor for the column. 当数据表中没有布尔列时,您也可以手动/以代码设置列的编辑器。

Example in code: 代码示例:
Say you add a devex grid column called "fCol". 假设您添加了一个名为“ fCol”的devex网格列。 The value for checked = "YES", unchecked = "NONO"; 选中的值=“ YES”,未选中的值=“ NONO”;

        GridColumn fCol = gridView1.Columns.Add();
        RepositoryItemCheckEdit fCheckEdit = new RepositoryItemCheckEdit();
        fCheckEdit.ValueChecked = "YES";
        fCheckEdit.ValueUnchecked = "NONO";
        fCol.ColumnEdit = fCheckEdit;
        fCol.FieldName = "Haganise";

Of course you can also do this in the designer. 当然,您也可以在设计器中执行此操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM