c# winform 如何从datagridview1中获得一行数据然后赋值到datagridview2中相应cell中? 如题
郁闷了.......
报错。不对
追答你不会直接贴我的代码吧,你的datagridview跟我不一样,列明也不一样的,这些都要改的,
追问我都改成自己的了 但还是不行 主要是[]里面报错
追答你把你的代码贴给我看看
追问类似这样的
string name = dataGridView2.CurrentRow.Cells[1].Value.ToString();
dataGridView2.CurrentRow.Cells[1].Value = name;
string ShangpinName = dataGridView2.CurrentRow.Cells[2].Value.ToString();
dataGridView2.CurrentRow.Cells[1].Value = ShangpinName;
怎么都是datagridview2啊,还有你是放在什么事件里的,要什么的效果,是选中1里面数据就往2里面存数据么
追问你有百度HI没有?
我贴错了
我这样写得
int id =int.Parse( dataGridView2.CurrentRow.Cells[0].Value.ToString());
dataGridView1.CurrentRow.Cells[0].Value = id;
string name = dataGridView2.CurrentRow.Cells[0].Value.ToString();
dataGridView1.CurrentRow.Cells[1].Value = name;
放在button点击事件里。
for (int i=0;i<dataGridView1.Columns.Count;i++)
{
dataGridView1.CurrentRow.Cells[i].Value =dataGridView2.CurrentRow.Cells[i].Value;
}
这么写不可以么
我这样写得
int id =int.Parse( dataGridView2.CurrentRow.Cells[0].Value.ToString());
dataGridView1.CurrentRow.Cells[0].Value = id;
string name = dataGridView2.CurrentRow.Cells[0].Value.ToString();
dataGridView1.CurrentRow.Cells[1].Value = name;
第二行和第四行提示:未将对象引用设置到对象的实例。 如何修改?
你是不是写反了。你不是要把dataGridView1相应的值赋给dataGridView2吗?
追问没写反,我的提问问反了。要把2中得赋值给1.
追答int id =int.Parse( dataGridView1.Rows[N]..Cells[0].Value.ToString());
id = dataGridView2.CurrentRow.Cells[0].Value ;
string name = dataGridView1.Rows[N].Cells[0].Value.ToString();
name= dataGridView2.CurrentRow.Cells[0].Value ;
明显这样写不对!!!
有text的属性么 大哥....
追答int id =int.Parse( dataGridView2.CurrentRow.Cells[0].Value.ToString());
dataGridView1.CurrentRow.Cells[0].Value = id;
string name = dataGridView2.CurrentRow.Cells[1].Value.ToString();
dataGridView1.CurrentRow.Cells[1].Value = name;
我这样写得
int id =int.Parse( dataGridView2.CurrentRow.Cells[0].Value.ToString());
dataGridView1.CurrentRow.Cells[0].Value = id;
string name = dataGridView2.CurrentRow.Cells[0].Value.ToString();
dataGridView1.CurrentRow.Cells[1].Value = name;
第二行和第四行提示:未将对象引用设置到对象的实例。 如何修改?