C# 选择 CategorizedAlphabetical 排序的 ProperyGrid 中的第一行
我已经加载了分类 PropertySpec 的 ProperyGrid 并设置为 CategorizedAlphabetical 排序。当表单运行类别时,类别内的项目将被排序。一个令人讨厌的现象是,PropertyGrid 默认情况下会在列表排序后选择第一个项目,有时它会将视图滚动到所选内容。如果项目列表很长,您最终会看到列表滚动到中间的某个位置。
由于 PropertySpec 可以在运行时创建,我希望始终在表单加载时显示列表的顶部。 PropertyGrid 不会“轻易”公开集合,当然也不会按有序顺序公开集合。经过谷歌搜索后,我相信这是不可能的?
I have ProperyGrid loaded with categorised PropertySpec and set to CategorizedAlphabetical sort. When form runs categories then items within categories are sorted. An annoying artefact is that PropertyGrid by default selects the first item after list was sorted and sometimes it scrolls view to selection. If item list is long you end up seeing list scrolled to somewhere in the middle.
Since PropertySpec can be created at runtime I want to always show the top of list on form load. PropertyGrid does not 'easily' expose collections and certainly not in ordered sequence. After googling around I am lead to believe this is not possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想出了下面的代码证明事实并非如此。
片段将选择排序列表的第一个类别。人们还可以选择该类别中的第一项来扩展该方法,但对于我的需要来说,这是不必要的。
希望这也能帮助其他人。
对列表进行排序后,实际选择类别的简化方法是使用
sortedCats[0].Select();
而不是循环并检查每个项目。如果您想使用该快捷方式,则必须断言列表不为空,但这会带来一些性能改进......I came up with below code which proves otherwise.
Snippet will select fist category of sorted list. One could also select first item in that category expanding on the method but for my needs that was unnecessary.
Hope this will help others as well.
The simplified method of actually selecting category once you have sorted list would be to
sortedCats[0].Select();
instead of looping through and checking each item. You would have to assert the list is not empty if you wanted to use that shortcut but that would gives some performance improvement...