Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DataGridView CellSelect and FullRowSelect

So I have several datagridviews that we had set to FullRowSelect. The users are now requesting the ability to select on single cells for copy functions.

I set the DataGridView to CellSelect but when I run the app, when I click on the Row Header it doesn't highlight the Full Row, only the first column.

I tried using the RowHeaderMouseClick with a CellMouseClick to get the selection mode to shift but in order for RowHeaderMouseClick to select it fully I am having to click on the row header multiple times.

private void DataGridView_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
    dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
}

How can I easily or not so easily switch back and forth between CellSelect and FullRowSelect depending on what they have selected on the grid?

like image 694
Taryn Avatar asked Dec 19 '11 20:12

Taryn


3 Answers

If I understand you, you want to be able to select single cells but also easily select a full row?

If that's the case, set SelectionMode to RowHeaderSelect.

like image 52
Igby Largeman Avatar answered Oct 19 '22 17:10

Igby Largeman


DataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;

1- You are actually using the DataGridView Structure, and not your object DataGridView.

2- The SelectionMode shouldn't be modified every time the user click a Row, but in your Constructor of your program.

Example

public MyForm()
{
    dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
}
like image 36
Martin Gemme Avatar answered Oct 19 '22 15:10

Martin Gemme


add this one line code.

this.dataGridView1.SelectionMode = isTrue == true ? DataGridViewSelectionMode.FullRowSelect : DataGridViewSelectionMode.RowHeaderSelect;
like image 39
Ramgy Borja Avatar answered Oct 19 '22 17:10

Ramgy Borja