WinForms dev express bind true/false 带有复选框的列
WinForms dev express bind true/false column with a checkbox
我正在处理一个 Windows Forms 项目,我在 XtraGrid.GridControl
中有一些数据,其中包含以下列:
ID
、Description
、To Process
我正在从数据库加载这些数据,To Process
列包含一个 boolean
字段。
我想要一个复选框来代替当前的 1
和 0
值,如果值为 1
则选中该复选框,如果值为 [=] 则取消选中19=].
如何使用 Dev Express 16
实现此目的?
这是我目前所做的:
- 在我的表单中导入了一个
DevExpress.XtraGrid.GridControl
Design
;
- 添加了三列
ID
、Description
和 To Process
;
使用此方法从 代码隐藏 填充 GridControl
DataSource
:
private void LoadTableData()
{
// initialization
gcTable.DataSource = null;
string query = " SELECT id, description, to_process FROM test_table ";
DataTable dt = Utils.ExecuteQuery(query);
if (dt != null && dt.Rows.Count > 0)
{
gcTable.DataSource = dt;
}
}
像现在一样,我填充了 table,但在 To Process
.
列中有 1
和 0
值
分配一个 RepositoryItemCheckEdit to your To Process
column's ColumnEdit property and set its ValueChecked and ValueUnchecked properties if necessary. More information here.
您可以使用 gridView1_CustomRowCellEdit
事件更改网格视图单元格的存储库。如果数据列是布尔类型,则网格控件的单元格将是复选框。
dt.Columns["to_process"].DataType = typeof(bool);
这是 CustomRowCellEdit 事件的示例代码。
void gridView1_CustomRowCellEdit(object sender, DevExpress.XtraGrid.Views.Grid.CustomRowCellEditEventArgs e)
{
if (e.Column.FieldName == "to_process")
{
DevExpress.XtraEditors.Repository.RepositoryItemCheckEdit repChk = new DevExpress.XtraEditors.Repository.RepositoryItemCheckEdit();
e.RepositoryItem = repChk;
}
}
我正在处理一个 Windows Forms 项目,我在 XtraGrid.GridControl
中有一些数据,其中包含以下列:
ID
、Description
、To Process
我正在从数据库加载这些数据,To Process
列包含一个 boolean
字段。
我想要一个复选框来代替当前的 1
和 0
值,如果值为 1
则选中该复选框,如果值为 [=] 则取消选中19=].
如何使用 Dev Express 16
实现此目的?
这是我目前所做的:
- 在我的表单中导入了一个
DevExpress.XtraGrid.GridControl
Design
; - 添加了三列
ID
、Description
和To Process
; 使用此方法从 代码隐藏 填充
GridControl
DataSource
:private void LoadTableData() { // initialization gcTable.DataSource = null; string query = " SELECT id, description, to_process FROM test_table "; DataTable dt = Utils.ExecuteQuery(query); if (dt != null && dt.Rows.Count > 0) { gcTable.DataSource = dt; } }
像现在一样,我填充了 table,但在 To Process
.
1
和 0
值
分配一个 RepositoryItemCheckEdit to your To Process
column's ColumnEdit property and set its ValueChecked and ValueUnchecked properties if necessary. More information here.
您可以使用 gridView1_CustomRowCellEdit
事件更改网格视图单元格的存储库。如果数据列是布尔类型,则网格控件的单元格将是复选框。
dt.Columns["to_process"].DataType = typeof(bool);
这是 CustomRowCellEdit 事件的示例代码。
void gridView1_CustomRowCellEdit(object sender, DevExpress.XtraGrid.Views.Grid.CustomRowCellEditEventArgs e)
{
if (e.Column.FieldName == "to_process")
{
DevExpress.XtraEditors.Repository.RepositoryItemCheckEdit repChk = new DevExpress.XtraEditors.Repository.RepositoryItemCheckEdit();
e.RepositoryItem = repChk;
}
}