【问题标题】:WinForms dev express bind true/false column with a checkboxWinForms dev express 使用复选框绑定真/假列
【发布时间】:2019-04-12 07:28:22
【问题描述】:

我正在处理一个 Windows 窗体 项目,我在 XtraGrid.GridControl 中有一些数据,其中包含这些列:

IDDescriptionTo Process

我正在从数据库中加载这些数据,To Process 列包含一个 boolean 字段。

我想用一个复选框代替当前的10 值,如果值为1 将被选中,如果值为0 则取消选中。

如何使用Dev Express 16 实现这一目标?


这是我到目前为止所做的:

  • 在我的表单Design 中导入了DevExpress.XtraGrid.GridControl
  • 添加了三列IDDescriptionTo Process
  • 使用此方法从后面的代码填充GridControlDataSource

    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;
      }
    }
    

到目前为止,我的表格已填充,但 To Process 列中包含 10 值。

【问题讨论】:

    标签: c# winforms devexpress


    【解决方案1】:

    RepositoryItemCheckEdit 分配给To Process 列的ColumnEdit 属性,并在必要时设置其ValueCheckedValueUnchecked 属性。更多信息here

    【讨论】:

    • 如何允许多选?谢谢!
    • 我明白了。我将ValueCheckedValueUncheckedtruefalse 更改为10
    【解决方案2】:

    您可以使用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;
            }
        }
    

    【讨论】:

      猜你喜欢
      • 2016-09-01
      • 2017-10-14
      • 1970-01-01
      • 2012-11-01
      • 2017-04-26
      • 2012-10-17
      • 2011-02-09
      • 1970-01-01
      • 2013-12-09
      相关资源
      最近更新 更多