RE: PropertyGrid dynamic Dropdown List
- From: v-lliu@xxxxxxxxxxxxxxxxxxxx (Linda Liu [MSFT])
- Date: Mon, 05 Feb 2007 04:52:17 GMT
Hi Phcmi,
I agree to what Nicolas has suggested.
When we override the methods, such as ConvertTo, ConvertFrom,
GetStandardValues and etc, in the derived TypeConverter class, we could get
the object that is connected with the type descriptor request through the
ITypeDescriptorContext parameter of the methods. So we could add a property
for the dynamic drop down list in the myProp class and then request it
later in the derived TypeConverter class.
The following is a sample. It requires that you add a PropertyGrid control
on the form in advance.
using System.ComponentModel;
using System.Drawing.Design;
public partial class Form1 : Form
{
public class myProp
{
string myStr;
[TypeConverter(typeof(MyConverter))]
public string MyItem
{
get { return myStr; }
set { myStr = value; }
}
List<string> list;
[Browsable(false)]
public List<string> MyList
{
get
{
if (list == null)
{
list = new List<string>();
list.Add("aaa");
list.Add("bbb");
list.Add("ccc");
}
return list;
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
myProp obj = new myProp();
this.propertyGrid1.SelectedObject = obj;
}
}
class MyConverter : TypeConverter
{
public override bool
GetStandardValuesSupported(ITypeDescriptorContext context)
{
return true;
}
public override StandardValuesCollection
GetStandardValues(ITypeDescriptorContext context)
{
List<string> list = (context.Instance as Form1.myProp).MyList;
StandardValuesCollection cols = new
StandardValuesCollection(list);
return cols;
}
}
Hope this helps.
If you have any question, please feel free to let me know.
Sincerely,
Linda Liu
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
.
- Follow-Ups:
- Re: PropertyGrid dynamic Dropdown List
- From: phcmi
- Re: PropertyGrid dynamic Dropdown List
- From: phcmi
- Re: PropertyGrid dynamic Dropdown List
- References:
- PropertyGrid dynamic Dropdown List
- From: phcmi
- PropertyGrid dynamic Dropdown List
- Prev by Date: Re: Remote Debugging
- Next by Date: Can the status of a printer be checked programtically in c#
- Previous by thread: Re: PropertyGrid dynamic Dropdown List
- Next by thread: Re: PropertyGrid dynamic Dropdown List
- Index(es):
Relevant Pages
|