abs_Z3r0

Hi!
I have a property in my class wich i would like to limit it's values to items that are read from a xml file.
in other words, i have an array that i read from a xml file and and i'd like to attach that to my property so i can choose from that list at design time.

thanks.



Re: Visual C# General limit property values

timvw

- Verify in the setter part of the property that the new value is really a value that exists in the xml file...
- Use a Combobox (Fill it with items that are in the xml file, DropDownStyle property set to DropDownList) so the user is restricted to valid choices....





Re: Visual C# General limit property values

abs_Z3r0

thanks, that's exactly what i want, but how do i associate the combo with the property




Re: Visual C# General limit property values

timvw

Here's a possible way:

assuming you have an xml file as following:



< xml version="1.0" encoding="UTF-8" >
<root>
<fruit>
<f_name>Lemon</f_name>
<f_color>Yellow</f_color>
</fruit>
<fruit>
<f_name>Grape</f_name>
<f_color>White</f_color>
</fruit>
</root>





DataSet dataSet = new DataSet();
dataSet.ReadXml("input.xml");

this.comboBox1.DisplayMember = "f_name";
this.comboBox1.DataSource = dataSet.Tables[0];









Re: Visual C# General limit property values

abs_Z3r0

thanks,
so if i understood correctly, my property type is going to be "ComboBox"
in this example is the ComboBox1




Re: Visual C# General limit property values

timvw

no, this code showed you how to populate a ComboBoxControl with values coming from the xml file..





Re: Visual C# General limit property values

abs_Z3r0

ok, i know that,
I need to know is how to make that combo appear in my property grid...
I need my property to be changed at design time (not at runtime) with the values from xml or Combo suposing i already have them in the Combo.

thanks




Re: Visual C# General limit property values

abs_Z3r0

Done it by using a custom editor as in this Example

thanks!