我试图获得的价值观细胞的数据表格的行我点和储存起来供以后使用,但似乎我不能得到它的工作。
击行上应该做的菜单出现在这我可以选择做一个行动与这些价值观。
这是什么我已经完成为止
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs x)
{
if (dataGridView1.Rows[x.RowIndex].Cells["Name"].Value != null) name = dataGridView1.Rows[x.RowIndex].Cells["Name"].Value.ToString();
else if (dataGridView1.Rows[x.RowIndex].Cells["LastName"].Value != null) last = dataGridView1.Rows[x.RowIndex].Cells["LastName"].Value.ToString();
}
private void dataGridView1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
if (last != null && name != null)
{
ContextMenu cm = new ContextMenu();
this.ContextMenu = cm;
cm.MenuItems.Add(new MenuItem("&Do something with those values in this row", new System.EventHandler(this.do_Action_with_values)));
cm.Show(this, new Point(e.X, e.Y));
}
last = null;
name = null;
}
}
删除:如果(最后一个!= 空&&名字!= null)
将使菜单的工作,但是,价值观不是保存,他们都为空。
是否有一个适当的方式存储在字符串中所列价值观的行被点击吗?