473,385 Members | 1,341 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

PropertyGrid dynamic Dropdown List

I have a PropertyGrid question. My task is to replace a legacy dialog
box presentation with a modern one. The dialog itself allows the user
to set [key/value] configuration settings in our application, so it
seems to me that a PropertyGrid is a perfect modern replacement. I won't
bore you with the details with all the controls on the dialog since I'm
only concerned with one issue. The legacy dialog contains a drop down
list control that is initialized with the same overall values but these
values depend the context of an external object selected before the
dialog is instantiated.
For example:
If the user selects widget FOO then the drop down list contains values
such as COM1 and COM2.
However if the user selects widget BAR the drop down list contains
values such as COM3 and COM4.
Further, if the user selects widget FOOBAR the drop down list contains
values such as COM1, COM2, COM3 and COM4.
This is a common scenario in the dialog box, since there are 6 other
drop down list controls
that behave similarly.
By the way, I'm writing this in C# in VSNet 2005 and the Property Grid
control is the standard one available in the IDE. One minor addition, my
supervisor has specified that the PropertyGrid control strategy should
be used as the model for a number of other issues, so I'm committed to
using the PropertyGrid control for the time being.

Here's how we've chosen to solve this issue in a PropertyGrid.
I'm attempting to use the same TypeConverter derived class on a property
to initialize the drop down list control with these different values .
Below is a sample of the code:

public class myProp
{
string myStr;
[TypeConverter(typeof(MyConverter)]
public string MyItem
{
get { return myStr;}
set { myStr = value;}
}
}

public class MyConverter : StringConverter
{
}

Above, Property MyItem represents the TypeConverter object that will
manage the values COM1,COM2, COM3, etc.

The problem is that instead of copying and pasting a ton of code,
thereby creating many different classes and capturing multiple
permutations, I want to implement one class, namely the myProp class to
solve this issue elegantly.
However, since I can't pass any parameters to the MyItem property not
can I pass any parameters to the MyConverter class, I'm at a dead end.
Does the nature of the PropertyGrid's declarative attributes also mean
that data values are somewhat hard coded as well or is there a solution
to my quandary? Should I shelve the PropertyGrid approach?
Any ideas or new strategies would be greatly appreciated.
Thanks
Feb 2 '07 #1
4 18782
Hello,

I hope that I understand the relationships between your classes...
Just wanted to propose something that could work for you. When your
Convert methods will be called in your TypeConverter you will get a
reference to a ITypeDescriptorContext. In there you have a property
called Instance that gives you a way to interrogate your myProp class
and ask it some informations like your selected widget. Does it fit
your design ?

Best regards,

Nicolas Cadilhac @ VisualHint (http://www.visualhint.com)
Home of Smart PropertyGrid for .Net and MFC
Microsoft PropertyGrid Resource List - http://
www.propertygridresourcelist.com
On Feb 2, 11:05 am, phcmi <p...@nospam.nospamwrote:
I have a PropertyGrid question. My task is to replace a legacy dialog
box presentation with a modern one. The dialog itself allows the user
to set [key/value] configuration settings in our application, so it
seems to me that a PropertyGrid is a perfect modern replacement. I won't
bore you with the details with all the controls on the dialog since I'm
only concerned with one issue. The legacy dialog contains a drop down
list control that is initialized with the same overall values but these
values depend the context of an external object selected before the
dialog is instantiated.
For example:
If the user selects widget FOO then the drop down list contains values
such as COM1 and COM2.
However if the user selects widget BAR the drop down list contains
values such as COM3 and COM4.
Further, if the user selects widget FOOBAR the drop down list contains
values such as COM1, COM2, COM3 and COM4.
This is a common scenario in the dialog box, since there are 6 other
drop down list controls
that behave similarly.
By the way, I'm writing this in C# in VSNet 2005 and the Property Grid
control is the standard one available in the IDE. One minor addition, my
supervisor has specified that the PropertyGrid control strategy should
be used as the model for a number of other issues, so I'm committed to
using the PropertyGrid control for the time being.

Here's how we've chosen to solve this issue in a PropertyGrid.
I'm attempting to use the same TypeConverter derived class on a property
to initialize the drop down list control with these different values .
Below is a sample of the code:

public class myProp
{
string myStr;
[TypeConverter(typeof(MyConverter)]
public string MyItem
{
get { return myStr;}
set { myStr = value;}
}

}

public class MyConverter : StringConverter
{

}

Above, Property MyItem represents the TypeConverter object that will
manage the values COM1,COM2, COM3, etc.

The problem is that instead of copying and pasting a ton of code,
thereby creating many different classes and capturing multiple
permutations, I want to implement one class, namely the myProp class to
solve this issue elegantly.
However, since I can't pass any parameters to the MyItem property not
can I pass any parameters to the MyConverter class, I'm at a dead end.
Does the nature of the PropertyGrid's declarative attributes also mean
that data values are somewhat hard coded as well or is there a solution
to my quandary? Should I shelve the PropertyGrid approach?
Any ideas or new strategies would be greatly appreciated.
Thanks

Feb 2 '07 #2
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<stringlist;

[Browsable(false)]
public List<stringMyList
{
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<stringlist = (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/subscripti...ult.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/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Feb 5 '07 #3
Hi Nicolas and Linda,
Thank you both for your replies. Nicolas, your suggestion worked very
well. This is precisely the solution we were searching for.
Linda, thanks for the added extras as well.
Phcmi

Linda Liu [MSFT] wrote:
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<stringlist;

[Browsable(false)]
public List<stringMyList
{
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<stringlist = (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/subscripti...ult.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/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
Feb 5 '07 #4
Hi Nicolas and Linda,
Thank you both for your replies. Nicolas, your suggestion worked very
well. This is precisely the solution we were searching for.
Linda, thanks for the added extras as well.
Phcmi

Linda Liu [MSFT] wrote:
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<stringlist;

[Browsable(false)]
public List<stringMyList
{
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<stringlist = (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/subscripti...ult.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/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
Feb 5 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Joseph Barron | last post by:
Here is a SIMPLE problem that I'm trying to solve. It works in Netscape 6.2, but IE6 gives ""No such interface supported." Below are page1.htm and page2.htm . In page1.htm, there are two...
7
by: Jeff Uchtman | last post by:
I know I have done this but my mind is fried. I have a dynamic dropdown in a form. I need to pull both the dynamic dropdown's ID and name listed in the dropdown. Need a little help with grey...
5
by: jung_h_park | last post by:
From: jung_h_park@yahoo.com Newsgroups: microsoft.public.dotnet.framework.aspnet Subject: Dropdown List not retaining its SelectedValue Date: Mon, 26 Jun 2006 21:02:57 -0700 Hello, My...
3
by: er1 | last post by:
Hi all, I have created a double dropdown list. Based on the first list selection, second list populates (this works fine). I have a submit button, which when clicked should run a select query...
3
by: dangutm | last post by:
how can i get data from a database into my dropdown list in a html form and and if i select from the first dropdown list the second dropdown load from the database the crosponding value of the...
4
by: PM ArunKumar | last post by:
i have two dropdown list in my form where the values in the list of second drop down changes based on the value i select in the first dropdown.(very similar to country and states list), here after...
0
by: Javilen | last post by:
Hello, Maybe one of you can offer a possible solution to the problem I have below. The request to me is to build a dynamically populating dropdown list from a text box.(something similar to...
3
by: fish919 | last post by:
Hello All, I am creating a date base in access. I want to create a dropdown list box that is connected to another dropdown list box. You start with a dropdown list that has 5 choices and each of...
2
by: raamay | last post by:
I want to have a dynamic dropdown box whose entries would depend on the selection of an entry in the first dropdown box. BUT the second dropdown box should not reload, only the entries inside should...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.