Add context menu in a datagrid view in a winform application

前端 未结 3 1438
小鲜肉
小鲜肉 2020-12-11 05:37

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 Ad

3条回答
  •  执念已碎
    2020-12-11 06:11

    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]);
        }
    

提交回复
热议问题