日期:2014-05-18 浏览次数:21056 次
DataTable dt = (DataTable)gridControl1.DataSource; dt.Columns.Add(new DataColumn("Check", typeof(bool)) { AllowDBNull = false, DefaultValue = false }); if (gridControl1.MainView.GetType() == typeof(GridView)) { GridView gridview = gridControl1.MainView as GridView; gridview.OptionsBehavior.Editable = true; //注意,这里将所有列设置为不可编辑,仅留下新增的勾选列运行编辑,如有特例,单独开启列编辑。 foreach (GridColumn gcol in gridview.Columns) { gcol.OptionsColumn.AllowEdit = false; } GridColumn col = gridview.Columns.Insert(0); col.Name = "Check"; col.FieldName = "Check"; col.Caption = "选择"; col.Width = 52; col.Visible = true; col.OptionsColumn.AllowEdit = true; col.OptionsColumn.AllowSize = false; col.OptionsColumn.AllowMove = false; col.OptionsColumn.AllowIncrementalSearch = false; col.OptionsFilter.AllowFilter = false; col.Fixed = FixedStyle.Left; }
------解决方案--------------------
DevExpress.XtraEditors.Repository.RepositoryItemCheckEdit cke = new DevExpress.XtraEditors.Repository.RepositoryItemCheckEdit();
setCheckEdit(gv_clist.Columns["选择"]);
private void setCheckEdit(DevExpress.XtraGrid.Columns.GridColumn column)
{
column.ColumnEdit = cke;
cke.AllowGrayed = false;
cke.ValueGrayed = "0";
cke.ValueChecked = "1";
cke.ValueUnchecked = "0";
}
------解决方案--------------------