MyComboBox inherrited from ComboBox

G

Guest

Example:

public class MyComboBox : System.Windows.Forms.ComboBox;
{
public bool CanDropDown = true;

public MyComboBox()
{
}
}

Prease help me how modify this class for if CanDropDown = false, the user
can not open the drop down list of the combobox.
I do'nt want to use the Enabled propertie.

Thank you!
 
M

Manohar Kamath

instead of using a public variable, use a public property

private book _canDropDown;

public bool CanDropDown
{
get
{
return _canDropDown;
}

set
{
// Set the internal value
_canDropDown = value;

// If the internal value if false, disable the dropdown
if (_canDropDown == false)
{
this.Enabled = false;
}
else
{
this.Enabled = true;
}
}
}
 
G

Guest

I don't want to use the Enabled property. I want to let Enabled = true,
but to denide drop down the combobox's dropdown list.
I tried to override OnDropDown() protected methode, but it's not working.

Example:

protected override void OnDropDown()
{
if (this.CanDropDown)
base.OnDropDown();
}

Thank you!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top