當前位置:歷史故事大全網 - 範文作文 - propertyGrid自定义排序以及[...]按钮的实现等

propertyGrid自定义排序以及[...]按钮的实现等

我明白你的第一个问题,但是后面两个不好意思没明白

第一个问题是这样的

//

/ / 摘要:

// 使用该集合的默认排序(通常为字母顺序)对集合中的成员进行排序。

public virtual PropertyDescriptorCollection Sort();

//

// 摘要:

// 使用指定的 System.Collections.IComparer 对此集合中的成员排序。

public virtual PropertyDescriptorCollection Sort(IComparer comparer);

//

// 摘要:

// 此集合中的成员排序。首先应用指定的顺序, 然后应用此集合的默认排序,右上角通常为字母顺序。

public virtual PropertyDescriptorCollection Sort(string[] names);

//

/ / 摘要:

// 此集合中的成员排序。然后首先应用指定的顺序,使用指定的 System.Collections.IComparer 进行排序。

public virtual PropertyDescriptorCollection Sort( string[] names, IComparer comparer);

///

/// 返回此类型说明符所表示的对象的已筛选属性的集合。

///

/// 初始化筛选器的属性数据库。它可以为空。< /p>

///

/// 一个 ,包含此类型说明符所表示的 对象的属性说明。默认为

///

public override PropertyDescriptorCollection GetProperties(Attribute[] attribute)

{

int i = 0;

//parameterList是格式化的待显示数据。

PropertyDescriptor[] newProps = new PropertyDescriptor[parameterList.Count];

foreach(参数列表中的ConfigParameter参数)

{

/ /由ConfigParameter,你自己定义的类型,转成PropertyDescriptor类型:

newProps[i++] = new SystemOptionsPropertyDescriptor(parameter, true, attribute);

}

< p> //取得了PropertyDescriptor[] newProps;现在可以对它排序,否则就按照newProps的原有顺序显示;

//1.直接返回

PropertyDescriptorCollection tmpPDC = new PropertyDescriptorCollection(newProps);

return tmpPDC;

//2.默认字母顺序

PropertyDescriptorCollection tmpPDC = new PropertyDescriptorCollection(newProps);

return tmpPDC.Sort();

//3.内存的顺序:sortName就是属性的顺序,内容就是各个属性名。

string[] sortName = new string[] { "a","b","c","d" };

return tmpPDC.Sort(sortName);

//4.comparer规则定义 的排序方式

ParameterListComparer myComp = new ParameterListComparer();//ParameterListComparer : IComparer

return tmpPDC.Sort(myComp);

//5.先 队列,后comparer

return tmpPDC.Sort(sortName,myComp);

//而我采用把数据整理之前就排序完毕的方法:即调用之前, 把数据参数列表排列好顺序,然后1.直接返回。

}

// 对于排序排序方法,可以声明一个事件,由外部确定属性的实现顺序:

public delegate string[] SortEventHandler ();

public class CustomTypeDescriptorExtend : CustomTypeDescriptor

{

public SortEventHandler OnSort;

//......其他 代码

public override PropertyDescriptorCollection GetProperties(Attribute[] attribute)

{

string[] sortName = OnSort();

PropertyDescriptorCollection tmpPDC = TypeDescriptor.GetProperties(typeof(CustomTypeDescriptorExtend), 属性);

return tmpPDC.Sort(sortName);

}

}

< p> //使用时:

public MyMethod()

{

CustomTypeDescriptorExtend s = new CustomTypeDescriptorExtend();

s. OnSort += new SortEventHandler(SetSortors);

PropertyGrid1.SelectedObject = s;

PropertyGrid1.PropertySort = PropertySort.Categorized;

}

< p> public string[] SetSortors()

{

return new string[] { "B", "A", "C" };

}

当然这也不是我写的,给你个原始链接吧,呵呵

/yangyuhang/blog/item/b2c8e3d3f88eb0dba9ec9add.html

  • 上一篇:《如果能再爱一次》最新txt全集下载
  • 下一篇:請問最早的平板電腦是哪個品牌的?
  • copyright 2024歷史故事大全網