繁体   English   中英

对DataGridView c#排序后,保持选定的行位置

[英]Maintain selected row position after sorting DataGridView c#

对DataGridView排序后,如何将所选行保持在现有位置?

我有在DatGridView的sorted事件上运行的代码。 它会记住选定的行并在网格中突出显示它,问题是它移动了行的位置。

if (!string.IsNullOrEmpty(customerCode))
{
    int itemFound = DGVBindingSource.Find("Code", customerCode); // Code is name of column to search.
    DGV.Position = itemFound;                    
}

我试过在下面添加代码行,但只是将行移到网格顶部。 我希望它保持原来的位置吗?

DGV.FirstDisplayedScrollingRowIndex = DGV.SelectedRows[0].Index;

任何帮助表示赞赏吗?

DevExpress GridView类可能对您的任务很有帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM