Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selecting a row in a DataGridView and having the arrow on the row header follow

This is in C#. If I select a row in a DataGridView with DataGridViewRow.Selected = true, the row selects just fine, but the arrow in the "column header" (the grey very leftmost column) doesn't follow. How do I set that?

Another question: If I set a column format to "centered" in the designer, the column header is still left aligned. How do I set the column header to be centered too?

Thanks, Brian

like image 611
BrianK Avatar asked Jul 16 '09 03:07

BrianK


2 Answers

This is straight from google:

In a DataGridView, the selected row and the current row (indicated by an arrow in the row header) may not be the same row. In addition, we could select multiple rows in a DataGridView but the current row can only be one row. When the SelectionMode property of the DataGridView is set to FullRowSelect, the current row will be always selected. If you'd like to change the current row in a DataGridView control, you may set the CurrentCell property
dataGridView1.CurrentCell = dataGridView1.Rows[1].Cells[0];
If you'd like to just change the selected row, you may set the Selected property of the row you want to true.
dataGridView1.CurrentRow.Selected = false;
dataGridView1.Rows[1].Selected = true;
like image 145
Kredns Avatar answered Oct 07 '22 04:10

Kredns


To answer the second part of you question, make sure your setting the header style for the column to centered as well.

like image 35
Kelsey Avatar answered Oct 07 '22 03:10

Kelsey