Hello开发人员我正在使用VS 2010。我有一个开发快速网格,其中我有一个复选框列。问题是当我选中复选框时会检查它但是当我移动到任何其他单元格或列时,复选框会自动获取未选中。现在我的代码如下
if (e.Column.ToString()=="Active" )
{
RepositoryItemCheckEdit edit = UserInfoGridView.GridControl.RepositoryItems.Add("CheckEdit") as RepositoryItemCheckEdit;
column = e.Column;
column.OptionsColumn.AllowSort = DevExpress.Utils.DefaultBoolean.False;
column.Visible = true;
column.VisibleIndex = 3;
column.FieldName = "CheckMarkSelection";
column.Caption = "Active";
column.OptionsColumn.ShowCaption = true;
column.OptionsColumn.AllowEdit = true;
column.OptionsColumn.AllowSize = false;
column.UnboundType = DevExpress.Data.UnboundColumnType.Boolean;
column.ColumnEdit = edit;
}
答案 0 :(得分:4)
我找到了答案.........我做的是这个
public frmLoad()
{
InitializeComponent();
string DisplayQuery = "Select * from TableName";
MasterDs = SqlHelper.ExecuteDataset(CommonClass.ConnectionString, CommandType.Text, DisplayQuery);
MasterDs.Tables[0].Columns.Add("FLAG", typeof(string));
MainGrid.DataSource = MasterDs.Tables[0];
gridview.PopulateColumns();
gridview.Columns["ID"].VisibleIndex = -1;
gridview.Columns["FLAG"].VisibleIndex = -1;
DevExpress.XtraEditors.Repository.RepositoryItemCheckEdit selectnew = new DevExpress.XtraEditors.Repository.RepositoryItemCheckEdit();
gridview.Columns["ColName"].ColumnEdit = selectnew;
selectnew.NullText = "";
selectnew.ValueChecked = "Y";
selectnew.ValueUnchecked = "N";
selectnew.ValueGrayed = "-";
}
答案 1 :(得分:0)
这可能是因为检查取消选中操作后,未绑定网格绑定的数据源。您是否处理视图的CellValueChanged
事件以更改darasource对象的属性值?
private void gridView1_CellValueChanged(object sender, CellValueChangedEventArgs e)
{
if (e.Column.Name != "Active")
return;
var person = gridView1.GetFocusedRow() as Person;
person.Active = Convert.ToBoolean(e.Value);
}
或者,如果您使用DataSet作为网格的数据源:
var id = gridView1.GetFocusedRowCellValue("IdColumnName");
var active = gridView1.GetFocusedRowCellValue("ActiveColumnName");
NorthwindDataSet.PersonsRow PersonsRow =
northwindDataSet1.Persons.FindByPersonID(id);
PersonsRow.ACTIVE= Convert.ToBoolean(active);
PS:未经测试
答案 2 :(得分:0)
试试这样 string DisplayQuery =“declare @Active bit; set @ Active = 0; select @Active as Active,* from TableName”;
答案 3 :(得分:0)
问题可能是由列的基础类型不正确引起的:它应该是bool
,可以开箱即用。
要设置类型,您可以尝试以下内容:
MasterDs.Tables[0].Columns[0].DataType = typeof(bool);
答案 4 :(得分:0)
我使用Entity Framework 6.1作为ObjectContext的后端。我已将数据库类型设置为tinyint,当实体框架更新类时,它会映射到byte。
将数据库类型更改为位并刷新实体对象会创建正确的布尔类型,之后复选框将在DevExpress Winforms中正确显示。