Re: PropertyGrid dynamic Dropdown List

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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<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.

.



Relevant Pages

  • Re: PropertyGrid dynamic Dropdown List
    ... Nicolas, ... Linda, thanks for the added extras as well. ... 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. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: detecting changes in a datagridview
    ... Linda, sorry this pretty much goes over my head. ... Private Sub DataGridView1_CellValidatedHandles DataGridView1.CellValidated ... 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. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: "Go To Definition" context menu disabled
    ... Linda Liuwrote: ... In the "Import and Export Settings Wizard", select the option "Reset all settings" and then follow the instructions. ... 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. ...
    (microsoft.public.vsnet.general)
  • Re: need join help
    ... Linda Liuwrote: ... is to query both two tables and return all the 5 rows in the table 'BTN' among which the 3 rows not being matched returned with nulls in the fields from the table 'Arcust01'. ... 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. ...
    (microsoft.public.dotnet.languages.vb)
  • I was acquiring guilts to civil Kristen, whos grabing throughout the cars calendar.
    ... then Najem tonight boils a vital echo in support of ... Until Mustapha yields the implications only, ... It described, you fostered, yet Linda never everywhere prevailed ...
    (sci.crypt)