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

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

问题描述

这是在C#中。如果我使用DataGridViewRow.Selected = true在DataGridView中选择一行,则该行选择的很好,但是列标题中的箭头(灰色最左边的列)并不遵循。另外一个问题是:如果我将列格式设置为居中,那么列标题仍然保持对齐。如何设置列标题为中心?



谢谢,
Brian

解决方案

直接来自谷歌

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

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

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



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



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



  dataGridView1.CurrentRow.Selected = false; 
dataGridView1.Rows [1] .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

解决方案

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;

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

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