我开发了一个Windows窗体应用程序,它有一个复选框的数据网格。如果我按下一个按钮,那么我想要获取所有已检查的行并对它们执行一些操作。 问题是,按下按钮时,它无法识别最新的复选框操作。这就像落后一步。Datagrid复选框单元格
我的代码是:
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查询 - 平常的东西。
请提供一些更多相关信息和代码。上面的内容并没有太多帮助。 – 2009-10-02 10:14:29