gpt4 book ai didi

c# - 数据网格复选框单元格

转载 作者:太空宇宙 更新时间:2023-11-03 14:34:43 24 4
gpt4 key购买 nike

我开发了一个 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 查询 - 通常的东西。

最佳答案

罗兰

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

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

关于c# - 数据网格复选框单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1508714/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com