在Form上拖放baiContextMenuStrip并添加一个“删除”菜单项,并添加此菜du单项的Click事件处理代码,如下zhi所示,设置DataGridView的ContextMenuStrip属性dao为新加入的ContextMenuStrip。
private void toolStripMenuItem_Click(object sender, EventArgs e) { DataGridView dv = sender as DataGridView; if (dv != null && dv.CurrentCell!=null && dv.CurrentCell.RowIndex!=-1) { dv.Rows.RemoveAt(dv.CurrentCell.RowIndex); } }
切记一定要设置DataGridView的ContextMenuStrip属性dao为新加入的ContextMenuStrip。
本文介绍如何在C#中为DataGridView控件添加一个右键菜单,并实现点击“删除”菜单项时删除当前选中行的功能。通过设置DataGridView的ContextMenuStrip属性并添加Click事件处理程序,可以轻松实现这一需求。
5213

被折叠的 条评论
为什么被折叠?



