private void dataGridView1_RowContextMenuStripNeeded(object sender, DataGridViewRowContextMenuStripNeededEventArgs e) { //若行已是选中状态就不再进行设置 if (dataGridView1.Rows[e.RowIndex].Selected == false) { dataGridView1.ClearSelection(); dataGridView1.Rows[e.RowIndex].Selected = true; } //判断是否在最下面的空白行上面,如果在的话则不显示右键菜单 if (e.RowIndex<dataGridView1.Rows.Count-1) { e.ContextMenuStrip = this.contextMenuStrip1; } }
- 本文标题: Winfrom C#添加右键菜单
- 文章分类:【WinForm/WPF】
- 非特殊说明,本文版权归【胡同里的砖头】个人博客 所有,转载请注明出处.