日期:2014-05-17  浏览次数:20638 次

datagridview中右击选中并传值?

右键执行的如下代码:
dataGridView1.CurrentRow.Selected = false;
dataGridView1.Rows[e.RowIndex].Selected = true;

取值用的如下代码:
dataGridView1.CurrentRow.Cells[0].Value.ToString();


取出的数据不对,取到了鼠标左键单击的那一行的数据,没取到右键选中的当前行,这个代码该怎么写?

------解决方案--------------------
右键执行的如下代码: 
dataGridView1.ClearSelection(); 
dataGridView1.Rows[e.RowIndex].Selected = true; 试试