在 DataGridView 中选择一行并在行标题上显示箭头 [英] Selecting a row in a DataGridView and having the arrow on the row header follow

查看:25
本文介绍了在 DataGridView 中选择一行并在行标题上显示箭头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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?

谢谢,布莱恩

推荐答案

这直接来自 google:

在 DataGridView 中,选中的行和当前行(由行标题中的箭头)可能不是同一行.此外,我们可以在 DataGridView 中选择多行但当前行只能是一行排.当 DataGridView 的 SelectionMode 属性设置为FullRowSelect,将始终选择当前行.如果您想更改 DataGridView 控件中的当前行,您可以设置 CurrentCell 属性
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];

如果你只想改变选中的行,你可以设置 Selected您想要为真的行的属性.
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;

这篇关于在 DataGridView 中选择一行并在行标题上显示箭头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆