Windows Develop Bookmark and Share   
 index > Windows Forms General > About Propertygrid--How can I sort the Category?
 

About Propertygrid--How can I sort the Category?

I am using the propertygrid to show the properties of my object which have categories.

But the sort of the categories is not correct.

For example, the properties of category A show before the properties of category B.

But actually , I want the category B show before A.

I have try theproperty ofpropertygridobject which namesPropertySort.But it can't fill my need.

Thank you!

xiaoaowanghu  Monday, July 23, 2007 10:28 AM

Hi

You should use character'\t'. Try something like :

Code Snippet

PropertyGridP

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

private void Form1_Load(object sender, EventArgs e)

{

MySize my = new MySize();

this.propertyGrid1.SelectedObject = my;

}

public class MySize

{

int width;

[DefaultValue(0), Category("A")]

public int Width

{

get { return width; }

set { width = value; }

}

int height;

[DefaultValue(0), Category("\t\t\t\t\t\t\tB")]

public int Height

{

get { return height; }

set { height = value; }

}

Size si;

[Category("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tC")]

public Size Si

{

get { return si; }

set { si = value; }

}

}

Hi

You should use character'\t'. Try something like :

Code Snippet

PropertyGridP

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

private void Form1_Load(object sender, EventArgs e)

{

MySize my = new MySize();

this.propertyGrid1.SelectedObject = my;

}

public class MySize

{

int width;

[DefaultValue(0), Category("A")]

public int Width

{

get { return width; }

set { width = value; }

}

int height;

[DefaultValue(0), Category("\t\t\t\t\t\t\tB")]

public int Height

{

get { return height; }

set { height = value; }

}

Size si;

[Category("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tC")]

public Size Si

{

get { return si; }

set { si = value; }

}

}

mhh, unfortunately if i use this method i get a small black bar infront of the category name. is there a better solution?

My categories contain numbers so i need to order them numeric. That means, 103 comes after 73...

Nico

Nico F.  Monday, June 02, 2008 2:07 PM

You can use google to search for other answers

Custom Search

More Threads

• rectangles draw incorrectly
• Updating a DataGridView with a string array
• Web Services and Remoting
• ChildIndex messed up in the Load event
• Help to generate dynamic textboxes and lines
• how a user control can be have a abnormal shape ?
• Retrieve listview collection item
• Defaulting button text (VS2005 / C#)
• Autosize of Label is not working
• Designer not like runtime