ฉันกำลังพยายามที่จะทำให้ค่าของเซลล์ของ datagrid แถวฉันคลิกบนและเก็บมันสำหรับใช้ในภายหลังแต่มันดูเหมือนฉันไม่สามารถเอามันไปทำงานแล้ว
การคลิกซ้อนควรจะทำให้เป็นเมนูปรากฎอยู่ซึ่งฉันสามารถเลือกที่จะทำเป็นการกระทำกับพวกนั้นค่า.
นี่คือสิ่งที่ผมเคยประสบความสำเร็จดังนั้นไกล
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;
}
}
ลบ:หาก(สุดท้าย!= โพรโทคอล aimcomment&&ชื่อของ!= โพรโทคอล aimcomment)
จะทำให้เมนูทำงานแต่งค่าของไม่ได้ช่วยไว้ทั้งหมดเป็นโพรโทคอล aimcomment.
มีเหมาะสมทางร้านอยู่ในใช้เส้นสายทั้งหมดคอลัมน์คุณค่าสำหรับคนแถวที่ถูกคลิก?