C# DataSet CheckBox Column With DevExpress DataGrid
Scenario
I have a DevExpress DataGrid which is bound to a DataSet in 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?
//(Di开发者_如何转开发splays "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....
Why do you use a Checkbox
column in your DataSet
?
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.
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".
The value for checked = "YES", unchecked = "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.
精彩评论