【问题标题】:Immediately update DataGridViewCheckBoxCell立即更新 DataGridViewCheckBoxCell
【发布时间】:2014-04-08 05:16:38
【问题描述】:

我正在以编程方式更新我的 WinForm DataGridView

问题,DataGridViewCheckBoxCell 没有更新!!!

我是谷歌,这看起来像是知道案例,但我尝试过的任何方法都没有帮助。

 private void InitializeFunctionsDataGrid()
    {


        System.Data.DataSet ds = func.GetFunctions();



        this.FunctionsDataGrid.DataSource = ds.Tables[0];
        this.FunctionsDataGrid.Columns["FunctionId"].Visible = false;
        this.FunctionsDataGrid.Columns["DESCRIPTION"].Width = 370;


         DataGridViewCheckBoxColumn column = new DataGridViewCheckBoxColumn();
            column.Name = "enable";
            column.HeaderText = "enable";
            column.FalseValue = 0;
            column.TrueValue = 1;
            FunctionsDataGrid.Columns.Add(column);



        foreach(DataGridViewRow row in FunctionsDataGrid.Rows)
        {

                 (( DataGridViewCheckBoxCell)row.Cells["enable"]).Value = 1;

        }

       FunctionsDataGrid.CurrentCell = null;

    }

【问题讨论】:

    标签: winforms datagridview datagridviewcheckboxcell


    【解决方案1】:

    enable 是未绑定的列。这意味着您需要自己提供单元格值。

    您可以将VirtualMode 属性设置为true 并处理CellValueNeeded 事件。
    如果你想让用户检查一个单元格,那么你需要处理CellValuePushed 事件。 作为DataGridView FAQ 一部分的DataGridView 示例具有未绑定复选框列以及数据绑定列的特定示例。

    【讨论】:

      【解决方案2】:

      好吧,对我来说基本上最简单的方法是使用数据源。 我已将该列添加到 DataTable 并用数据填充它。 然后最后一件事 this.FunctionsDataGrid.DataSource = ds.Tables[0];

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-01-06
        • 1970-01-01
        • 2016-08-06
        • 1970-01-01
        • 2018-11-08
        • 2018-06-04
        • 2018-07-25
        • 2012-09-22
        相关资源
        最近更新 更多