?? on PropertyGrid - Bob Powell [MVP] |
10-Jan-08 02:39:28
|
You should be able to implement your own TypeConverter based object for the
enum and get it to return standard values in the order you want.
--
--
Bob Powell [MVP]
Visual C#, System.Drawing
Ramuseco Limited .NET consulting
http://www.ramuseco.com
Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm
Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm
All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article. |
 |
| |
?? on PropertyGrid - Harold Demure |
10-Jan-08 05:52:39
|
yes.. i did read about the ITypeConverter (??) interface and how you have to
implement it but the term 'type converter' i didn't directly relate to
're-sort'. but i'll take another look. thanx.. |
 |
| |
?? on PropertyGrid - Claes Bergefall |
10-Jan-08 07:08:24
|
It's pretty easy actually. All you need to do is inherit a new class from
EnumConverter and override it's GetStandardValues method. In the
GetStandardValues method just create a list of your enum type, add the
values in the order you want them and then return the list.
Once you have that use the TypeConverterAttribute to attach the converter to
your enum.
/claes |
 |
| |
There is a simpler way - Robbe Morris - [MVP] C# |
10-Jan-08 08:54:50
|
to create complex user interfaces with the PropertyGrid
control without monkeying with your classes.
http://www.eggheadcafe.com/tutorials/aspnet/270e9432-d236-47e7-b1af-5cd3abe27a75/net-propertygrid-control.aspx
--
Robbe Morris [Microsoft MVP - Visual C#]
AdvancedXL Server, Designer, and Data Analyzer
Convert cell ranges in Excel to rule driven web surveys
Free download: http://www.equalssolved.com/default.aspx |
 |
| |
?? on PropertyGrid - Harold Demure |
10-Jan-08 12:54:18
|
thanx for all the ideas.. |
 |
| |
?? on PropertyGrid - Harold Demure |
10-Jan-08 03:41:00
|
question on returning the new list.. the return value is a
StandardValuesCollection whose valueArray and values members are hidden.
since i assume i'd have to somehow update the svc object with my new list,
how would i do that with the necessary members not accessible??
i was psyched that i got this far but now i'm stuck on the most important
part. |
 |
| |
?? on PropertyGrid - Harold Demure |
10-Jan-08 09:05:05
|
ok here's what i got.. maybe it wasn't what you had in mind but i felt i
wanted to physically sort the original enum as opposed to hardcoding a new
one in the right order. but anyway, this blows up with a {" is not a valid
value for TestList."} error. apparently it sees a null value somewhere. any
ideas?
namespace PropGridTest
{
[TypeConverter(typeof(MyEnumConverter))]
public enum TestList
{
GHI = 0,
ABC = 1,
DEF = 2,
}
public class PropsClass
{
private TestList _prop1;
public TestList Prop1
{
get { return _prop1; }
set { _prop1 = value; }
}
}
public class MyEnumConverter : EnumConverter, IComparer
{
public MyEnumConverter(Type type)
: base(type)
{
}
public override StandardValuesCollection
GetStandardValues(ITypeDescriptorContext context)
{
string[] list = new string[3];
list = Enum.GetNames(typeof(TestList));
Array.Sort(list, this);
Values = new StandardValuesCollection(list);
return Values;
}
#region IComparer Members
public int Compare(object x, object y)
{
string sx = (string)x;
string sy = (string)y;
return sx.CompareTo(sy);
}
#endregion
}
} |
 |
| |
?? on PropertyGrid - Claes Bergefall |
11-Jan-08 04:46:47
|
The returned list must contain values of your enum type (i.e. TestList), not
string. I'm guessing that's why it blows up. Try this:
public class TestListConverter : EnumConverter, IComparer<string>
{
public TestListConverter(Type type) : base(type)
{
}
public override StandardValuesCollection
GetStandardValues(ITypeDescriptorContext context)
{
string[] names = Enum.GetNames(typeof(TestList));
Array.Sort<string>(names, this);
List<TestList> values = new List<TestList>();
foreach (string name in names)
values.Add((TestList)Enum.Parse(typeof(TestList), name));
return new
System.ComponentModel.TypeConverter.StandardValuesCollection(values);
}
public int Compare(string x, string y)
{
return String.Compare(x, y);
}
}
/claes |
 |
| |
?? on PropertyGrid - Harold Demure |
11-Jan-08 06:35:13
|
awesome man.. it works.. thanx a bunch.. |
 |
| |