Right click to select a row in a Datagridview and show a menu to delete it

后端 未结 12 678
梦毁少年i
梦毁少年i 2020-12-02 12:00

I have few columns in my DataGridView, and there is data in my rows. I saw few solutions in here, but I can not combine them!

Simply a way to right-click on a row, i

12条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-02 12:32

    private void dataGridView1_CellContextMenuStripNeeded(object sender, 
    DataGridViewCellContextMenuStripNeededEventArgs e)
    {            
        if (e.RowIndex != -1)
        {
            dataGridView1.ClearSelection();
            this.dataGridView1.Rows[e.RowIndex].Selected = true;
            e.ContextMenuStrip = contextMenuStrip1;
        }
    }
    

提交回复
热议问题