【问题标题】:Datagrid checkbox cell数据网格复选框单元格
【发布时间】:2009-11-20 05:28:10
【问题描述】:

我开发了一个 Windows 窗体应用程序,它有一个带有复选框的数据网格。如果我按下一个按钮,那么我想获取所有选中的行并对它们进行一些操作。 问题是当按钮被按下时它不能识别最新的复选框动作。这就像落后了一步。

我的代码是:

    private void copyToToolStripMenuItem_Click(object sender, EventArgs e)
    {
        dataGridView1.ClearSelection();
        DialogResult result = this.folderBrowserDialog1.ShowDialog();
        if (result == DialogResult.OK)
        {
            string foldername = this.folderBrowserDialog1.SelectedPath;
            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                if (row.Cells[0].Value != null)
                {
                    if ((bool)row.Cells[0].Value == true)
                    {
                        try
                        {
                            string[] vars = row.Cells[1].Value.ToString().Split('\\');
                            System.IO.File.Copy(row.Cells[1].Value.ToString(), foldername + @"\" + vars[vars.Length - 1], true);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.ToString());
                        }
                    }
                }
            }
        }
    }

数据来自 SQL 查询 - 常见的东西。

【问题讨论】:

  • 请提供更多相关信息和代码。以上内容并没有太大帮助。

标签: c# .net winforms datagridview checkbox


【解决方案1】:

罗兰,

原因可能是数据尚未提交到源。 DataGridView 的工作方式是它“绑定”到源并保持数据同步。但是,在 DataGridView 中所做的更改不会立即更新 DataGridView。它被认为是“肮脏的”。

更改后尝试检查原始数据源,您也可以尝试调用 BindingContext(..).EndCurrentEndit();或类似的尝试并确保数据已提交。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-13
    • 1970-01-01
    • 1970-01-01
    • 2016-05-30
    • 2011-04-18
    • 2012-03-11
    相关资源
    最近更新 更多