H
H
h1_0ne2019-03-01 20:48:42
C++ / C#
h1_0ne, 2019-03-01 20:48:42

How to select a cell on RMB in DataGridView?

By clicking on the LMB on the DGV, a cell in the DGV is selected, the CellMouseClick event is called, and so on. When the right mouse button is pressed, all OnMouse... CellMouse... are called, but the cell is not selected. How to fix it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
Foggy Finder, 2019-03-01
@FoggyFinder

One of the options:

private void dataGridView1_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
{
    if (e.Button == MouseButtons.Right)
    {
        dataGridView1.ClearSelection();
        dataGridView1[e.ColumnIndex, e.RowIndex].Selected = true;
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question