C# 如何将 DataGridView 定位到特定行(以便所选行位于顶部)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/795181/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 01:29:43  来源:igfitidea点击:

How do I position a DataGridView to a specific row (so that the selected row is at the top)

c#.netdatagridviewuser-interface

提问by Michael Todd

I have an application with a DataGridView on it and I would like to position the rows such that a specific row is at the top of the list.

我有一个带有 DataGridView 的应用程序,我想定位行,使特定行位于列表顶部。

I don't want a sort, I want a way to programmatically tell the DataGridView "scroll to the Nth row."

我不想要排序,我想要一种以编程方式告诉 DataGridView“滚动到第 N 行”的方法。

Any ideas?

有任何想法吗?

采纳答案by Marc Gravell

回答by BFree

The DataGridView has a property called: FirstDisplayedScrollingRowIndex. Set that, and the row will then be at the top of the list.

DataGridView 有一个名为:FirstDisplayedScrollingRowIndex 的属性。设置它,然后该行将位于列表的顶部。