【问题标题】:Selecting a row in a DataGridView and having the arrow on the row header follow在 DataGridView 中选择一行并在行标题上显示箭头
【发布时间】:2010-11-11 05:47:38
【问题描述】:
这是在 C# 中。如果我使用 DataGridViewRow.Selected = true 在 DataGridView 中选择一行,则该行选择得很好,但“列标题”(最左边的灰色列)中的箭头不跟随。如何设置?
另一个问题:如果我在设计器中将列格式设置为“居中”,列标题仍然是左对齐的。如何将列标题也设置为居中?
谢谢,
布赖恩
【问题讨论】:
标签:
c#
.net
winforms
datagridview
header-row
【解决方案1】:
这是直接来自google:
在 DataGridView 中,选定的行和当前行(由
行标题中的箭头)可能不是同一行。此外,我们可以
在 DataGridView 中选择多行,但当前行只能是一个
排。
当 DataGridView 的 SelectionMode 属性设置为
FullRowSelect,当前行将始终被选中。
如果您想更改 DataGridView 控件中的当前行,您可以
设置 CurrentCell 属性
dataGridView1.CurrentCell = dataGridView1.Rows[1].Cells[0];
如果您只想更改选定的行,您可以设置 Selected
您想要为真的行的属性。
dataGridView1.CurrentRow.Selected = false;
dataGridView1.Rows[1].Selected = true;
【解决方案2】:
要回答您问题的第二部分,请确保将列的标题样式也设置为居中。