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

本秂侑毒 提交于 2019-12-17 23:27:54

问题


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


回答1:


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;



回答2:


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



来源:https://stackoverflow.com/questions/1135304/selecting-a-row-in-a-datagridview-and-having-the-arrow-on-the-row-header-follow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!