0

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!

pradeepradyumna
  • 952
  • 13
  • 34
  • _CellContentClick_ Is really serious about its name. Never recommended. _But the selection wasn't happening properly. It would disappear as soon as I click._ Not properly?? Clicked where??? – TaW Apr 23 '17 at 10:07
  • @TaW CellContentClick is an event I'm referring to here. And I'm clicking on the rows of the DataGridView. When I click, the selection is not persistent. It goes away quickly. And we won't be able to see if something was selected. – pradeepradyumna Apr 23 '17 at 10:19

1 Answers1

1

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!

TaW
  • 53,122
  • 8
  • 69
  • 111