在 DataGridView 中选择一行并让行标题上的箭头跟随

发布于 2024-07-27 19:46:12 字数 206 浏览 8 评论 0原文

这是在 C# 中。 如果我在 DataGridView 中使用 DataGridViewRow.Selected = true 选择一行,则该行选择得很好,但“列标题”(最左边的灰色列)中的箭头不会跟随。 我该如何设置呢?

另一个问题:如果我在设计器中将列格式设置为“居中”,列标题仍然保持左对齐。 如何将列标题设置为居中?

谢谢, 布莱恩

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

逆光下的微笑 2024-08-03 19:46:12

这直接来自 google

在 DataGridView 中,所选行和当前行(由
行标题中的箭头)可能不是同一行。 此外,我们还可以
在 DataGridView 中选择多行,但当前行只能是一行
排。

当 DataGridView 的 SelectionMode 属性设置为
FullRowSelect,当前行将始终被选中。

如果您想更改 DataGridView 控件中的当前行,您可以
设置 CurrentCell 属性

dataGridView1.CurrentCell = dataGridView1.Rows[1].Cells[0];

如果您只想更改选定的行,您可以设置 Selected
您想要为 true 的行的属性。

dataGridView1.CurrentRow.Selected = false;
dataGridView1.Rows[1].Selected = true;

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;
橘虞初梦 2024-08-03 19:46:12

要回答问题的第二部分,请确保将列的标题样式也设置为居中。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文