我想选择一个datagridview行并将值复制到3文本框。如何将值从Datagridview选定行复制到文本框
我试过这个代码(它在另一个我的项目中工作),但我得到一个错误。这是代码:
private void DataGridView2_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex >= 0)
{
DataGridViewRow row = this.DataGridView2.Rows[e.RowIndex];
textBox1.Text = row.Cells["HomeNM"].Value.ToString();
textBox3.Text = row.Cells["HostNM"].Value.ToString();
fromTxt.Text = row.Cells["odd1NM"].Value.ToString();
}
}
这是我的错误:
Error 1 ' bexscraping.Form1 ' does not contain a definition of ' DataGridView2 ' and has not been found no extension method ' DataGridView2 ' accepting a first argument of type ' bexscraping.Form1 ' . Probably missing a using directive or a reference to an assembly.
我不知道哪里是错误 - 任何想法?
编辑:我忘了初始化我的datagridview; M现在我的代码正在工作!不管怎样,谢谢!
我看不出有任何问题与您的代码,有一件事我可以问,你有名字''DataGridView'在DataGridView2'你的项目? –
正确的名称是:dataGridView2 – Marci
这就是问题所在,请尝试使用'DataGridViewRow row = this.dataGridView2.Rows [e.RowIndex];' –