Able to select a row but shouldn't select the last column in that row in a DataGridView

339 views Asked by At

I have DataGridView with about 5 columns and the last column is a DataGridViewLinkColumn type. So the requirement here is that I should be able to select any row I want and when I do that, all the columns should be selected except the last column in that selected row. As the last column contains a hyperlinked text and there are some functions written which are intended to run.

Currently I have set the selection mode to FullRowSelect.

To achieve the requirement I have tried to set the mode to CellSelect and in the CellContentClick I was setting 'Selected' property for the specific columns of a selected row. But the selection wasn't happening properly. It would disappear as soon as I click. Also I tried to put the same logic in CellMouseUp, but it did't work either.

Kindly suggest me ways or workarounds for achieving the requirement.

Many Thanks!

1

There are 1 answers

0
TaW On BEST ANSWER

First set the SelectionMode to CellSelect. Then code the SelectionChanged event:

private void dataGridView1_SelectionChanged(object sender, EventArgs e)
{
    foreach (DataGridViewCell c in dataGridView1.CurrentRow.Cells)
            c.Selected = c.ColumnIndex != 4;
}

Note that this makes no provisions for deselecting a row!