我開發了一個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