ugp

How to add a dropdown list in the design time..so that the user will be able to set its propertise in the design time.

(The dropdown list should be apper in the propertise window.)

Like this;

When add a usercontrol to the Form...and select that usercontrol. in that case should able to set the propertise of the usercontrol through the dropdown list....

how to do this!!!

Better if anyboay canhelp with an example.



Re: Windows Forms General Add a dropdown list at Design time

NitinMahajan

Hi,

If I understand your requirement clearly it can be achieved in following steps:

1. Create one enumerator like below:

Code Snippet
public
enum FormatType { None, General, Text, Currency, Percentage, MMDDYYYY, MMDDYY}

2. In your usercontrol class declare one variable of this enumerator type and expose it using public property like:

Code Snippet

private FormatType m_eTextFormat;

[Category("Formatting"), DefaultValue(FormatType.None)]

public FormatType TextFormat

{

get { return m_eTextFormat; }

set { m_eTextFormat = value; }

}

3. Now when you select the User Control, in the properties window you will see new property named TextFormat with dropdown showing all values of enumerator.

Thanks,

Nitin






Re: Windows Forms General Add a dropdown list at Design time

ugp

thanks; Nitin.

It works.

by using that code i was able to get the dropdown list in the design view.

But i was unable to get the selected value. (say; when select the second element of the dropdown list, i want to print that value in a textbox. - if user select "General" from the dropdown list...how to print that on a textbox. - just assume textbox also a part of the user control.)

i tred in various ways...but unable to do it.

pls help!..hoping for a reply.





Re: Windows Forms General Add a dropdown list at Design time

NitinMahajan

Please modify the Public property as follows:

Code Snippet

[Category("Formatting"), DefaultValue(FormatType.None)]

public FormatType TextFormat

{

get { return m_eTextFormat; }

set

{

m_eTextFormat = value;

this.textBox1.Text = m_eTextFormat.ToString();

}

}

Thanks,

Nitin