C#中选择第一行CategorizedAlphabetical分类ProperyGrid [英] C# Selecting first row in CategorizedAlphabetical sorted ProperyGrid

查看:250
本文介绍了C#中选择第一行CategorizedAlphabetical分类ProperyGrid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经ProperyGrid加载分类PropertySpec并设置为CategorizedAlphabetical排序。当运行形式种类然后类别中的项目进行排序。一个恼人的假象是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.

由于PropertySpec可以在运行时创建我要始终显示列表上形成顶加载。 PropertyGrid中不易揭露收藏和肯定不会在有序序列。周围的Googling后,我带领相信这是不可能的?

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?

推荐答案

我想出了下面这证明,否则代码。

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.

// bind the PropertyTable to PropertyGrid
this.pg_Prefs.SelectedObject = proptable;

// get selected item
GridItem gi = this.pg_Prefs.SelectedGridItem;
// get category for selected item
GridItem pgi = gi.Parent.Parent;

//sort categories
List<GridItem> sortedCats = new List<GridItem>(pgi.GridItems.Cast<GridItem>());
sortedCats.Sort(delegate(GridItem gi1, GridItem gi2) { return gi1.Label.CompareTo(gi2.Label); });

// loop to first category
for (int i = 0; i < pgi.GridItems.Count; i++)
{
    if (pgi.GridItems[i] == gi) break; // in case full circle done
    // select if first category
    if (pgi.GridItems[i].Label == sortedCats[0].Label)
    {
         pgi.GridItems[i].Select();
         break;
    }
}



希望这将有助于其他人。

Hope this will help others as well.

其实选择类别,一旦你排序列表将简化方法 sortedCats [0]。选择(); 而不是通过循环和检查每个项目。你将不得不断言该列表不为空,如果你想使用快捷键但会给出了一些性能改进...

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...

这篇关于C#中选择第一行CategorizedAlphabetical分类ProperyGrid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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