在写C#窗体应用的时候,想要获取datagridview中选定的单元格所在行的数据,
s1 = dataGridView1.CurrentRow.Cells[0].Value.ToString();
s2 = dataGridView1.CurrentRow.Cells[1].Value.ToString();
s3 = dataGridView1.CurrentRow.Cells[2].Value.ToString();
s4 = dataGridView1.CurrentRow.Cells[3].Value.ToString();
s5 = dataGridView1.CurrentRow.Cells[4].Value.ToString();
s6 = dataGridView1.CurrentRow.Cells[5].Value.ToString();
在使用上面代码的时候发现这一些代码不灵敏,有时候单击单元格就能够显示单元格的内容,有时候单击单元格s1等的值还是上一次选择单元格的内容。这样应该如何改进,或者换一种怎样的更好的方法获取选中单元格的一行的数据更为灵敏呢
Grid.Rows[Grid.Rows.Count - 1].Activate();你可以把它设置为活动行。默认选中的。
鼠标问题,不是代码问题