Tıkladığım bir datagrid satırının hücrelerinin değerlerini almaya ve daha sonra kullanmak üzere saklamaya çalışıyorum, ancak çalışmasını sağlayamıyorum gibi görünüyor.
Satıra tıklamak, bu değerlerle bir eylem yapmayı seçebileceğim bir menünün görünmesini sağlamalıdır.
Şimdiye kadar başardığım şey buydu.
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;
}
}
Kaldırma: eğer (son != null & & isim != boş)
Menünün çalışmasını sağlar, ancak değerler kaydedilmez, hepsi boştur.
Tıklanan satır için tüm sütun değerlerini dizelerde saklamanın doğru bir yolu var mı?