datagridview 如何实现双击行中的特定单元格 跳到另一个页面

public int r;

private void dataGridView1_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
{
r = Convert.ToInt32(dataGridView1.SelectedCells[0].Value);
员工详细信息 x = new 员工详细信息();
x.ShowDialog();

}为什么双击第一个单元格会跳转到另一个页面 双击其他单元格只要是数字也会跳转呀

写datagridview单元格双击事件,在事件里获取你所指的特定单元格即可。这里的特定,可以是指定的行、列或者存在特殊值(数据库返回数据、颜色、自动编号等等)的单元格。追问

public int r;
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
r = Convert.ToInt32(dataGridView1.SelectedCells[0].Value);
Form2 id = new Form2();
id.ShowDialog();

}
为什么双击数字就会跳转到另一个页面 双击文字就不会跳转

追答

晕,你双击文字,在你那段程序里Convert.ToInt32的时候就出错了。。当然弹不出id界面,你调试的时候VS应该有报错吧。。再者说,你不给弹出窗口传值,那ID取出来做什么。
还有,你写的是CellContentClick事件,这个是指双击单元格内容时才触发,我觉得不如直接CellMouseDoubleClick这种双击(或者去写那个单击)事件好用。

还有,活用这里的DataGridViewCellEventArgs e,可以轻松获取你当前点的单元格Index或者坐标值。

温馨提示:内容为网友见解,仅供参考
第1个回答  2011-05-13
就是写一个双击事件,然后获取这一行的标识,传值到另外一个页面追问

public int a;

private void dataGridView1_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
{
a = Convert.ToInt32(dataGridView1.SelectedCells[0].Value);
form2 x = new form2 ();
x.bs = bs;
x.ShowDialog();
}为什么双击整型的字段能跳转到另一个页面 双击文字就不会跳转呀

追答

你得设置dataGridView1选择整行啊

第2个回答  2011-05-15
在 private void dataGridView1_CellContentDoubleClick单元格双击事件中写追问

public int r;

private void dataGridView1_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
{
r = Convert.ToInt32(dataGridView1.SelectedCells[0].Value);
员工详细信息 x = new 员工详细信息();
x.ShowDialog();

}为什么双击第一个单元格会跳转到另一个页面 双击其他单元格只要是数字也会跳转呀

第3个回答  2011-05-13
很简单了哈!你直接在你
DataGridView的单元格的双击事件用赋值语句就是了
DataGridView1.curentcell就可以访问当前单元格了哈
追问

public int r;

private void dataGridView1_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
{
r = Convert.ToInt32(dataGridView1.SelectedCells[0].Value);
员工详细信息 x = new 员工详细信息();
x.ShowDialog();

}为什么双击第一个单元格会跳转到另一个页面 双击其他单元格只要是数字也会跳转呀

相似回答