Hello, I have a custom combo box class.
In some cases I need it to be disabled without being grayed and in some others I need it to be enabled with loaded data of a data source of sql server database through a sql query.
So I thought about this, to go inside my custom class
and create a custom MouseMove event in order to make it loose focus when I want to disable it. But I don't know how to override it, because I have an additional argument of bool type the Disable.
private void CustomCbo_MouseMove(object sender, MouseEventArgs e, bool Disable)
{
if (Disable)
{
this.Parent.Focus();
this.SelectionLength = 0;
}
}
However I found on another site the following, it's ok, but I don't understand it very well and I need the oppossite too, in order to enable the
CustomCombo so that to have the appropriate values of datasource of my database.
public void DisableComboWithoutGrayedOut()
{
this.DropDownHeight = 1;
this.KeyDown += (s, e) => e.Handled = true;
this.KeyPress += (s, e) => e.Handled = true;
this.KeyUp += (s, e) => e.Handled = true;
}
In case I use the Enabled property it's ok, but I don't like to be grayed out. And ComboBox doesn't have a ReadOnly property like textboxes.
Any suggestion and explanation for both ways please, will be much appreciated. Thank you so much in advanced.
What I have tried:
private void CustomCbo_MouseMove(object sender, MouseEventArgs e, bool Disable)
{
if (Disable)
{
this.Parent.Focus();
this.SelectionLength = 0;
}
}
public void DisableComboWithoutGrayedOut()
{
this.DropDownHeight = 1;
this.KeyDown += (s, e) => e.Handled = true;
this.KeyPress += (s, e) => e.Handled = true;
this.KeyUp += (s, e) => e.Handled = true;
}