在 winform 应用程序的数据网格视图中添加上下文菜单 [英] Add context menu in a datagrid view in a winform application
本文介绍了在 winform 应用程序的数据网格视图中添加上下文菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在 DataGridView 中右键单击菜单项时显示上下文菜单?我想在菜单中添加删除,以便可以删除整行.提前致谢
How to show a Context Menu when you right click a Menu Item in a DataGridView ? I would like to add delete in the menu so that the entire row can be deleted . Thanks in Advance
推荐答案
参考 Miguel 的回答
我认为这很容易实现
With reference to Miguel answer
I think this will be easy to implement like this
int currentRowIndex;
private void dataGridView1_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e)
{
currentRowIndex = e.RowIndex;
}
private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
{
dataGridView1.Rows.Remove(dataGridView1.Rows[currentRowIndex]);
}
这篇关于在 winform 应用程序的数据网格视图中添加上下文菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文