WinFrom - DataGridView控件右键选中记录并弹出菜单

dataGridView右键菜单并选中该行



程序代码:



private void dataGridView1_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)

        {

            if (e.Button == MouseButtons.Right)

            {

                if (e.RowIndex >= 0)

                {

                    dataGridView1.ClearSelection();

                    dataGridView1.Rows[e.RowIndex].Selected = true;

                    dataGridView1.CurrentCell = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex];

                    contextMenuStrip1.Show(MousePosition.X, MousePosition.Y);

                }

            }

        }



 



去掉带*好的左边的那一列:



把DataGridView 的RowHeadervisible设置成false

 

你可能感兴趣的:(datagridview)