I want to show a drop-down of strings in a propertygrid for a selected value. In my current case, I have to bind a dictionary object to a property grid.
If I am binding a class it is easy to do as below using a TypeConverter.
public class Employee
{
public string Name { get; set; }
[TypeConverter(typeof(JobCategoryConverter))]
public int? Category { get; set; }
}
private void Form1_Load(object sender, EventArgs e)
{
Employee emp = new Employee() {Name = "Ray" ,Category = 1 };
propertyGrid1.SelectedObject = emp;
}
result look like this.
Any suggestion how I can show this dropdown if I bind to a dictionary? I used this code to bind dictionary to propertygrid.
So the code looks like,
private void Form1_Load(object sender, EventArgs e)
{
IDictionary dict = new Hashtable();
dict["Name"] = "Ray";
dict["Category"] = 1;
DictionaryPropertyGridAdapter dpg = new DictionaryPropertyGridAdapter(dict);
propertyGrid1.SelectedObject = dpg;
}