Disable toolstripmenuitem

  • Thread starter Thread starter Andrus
  • Start date Start date
A

Andrus

I placed Combobox to winforms DataGridView using DataGridViewComboBoxColumn
and other controls.

My combobox class contains code to enable/disable button in form.

OnEnter and OnLeave events fire but button is never grayed out.
How to make button active only if combobox column is active ?

Andrus.

class MyCombo: ComboBox {

protected override void OnEnter(System.EventArgs e) {

((BrowseForm)FindForm()).OpenSelection.Enabled = true;

base.OnEnter(e);

}

protected override void OnLeave(System.EventArgs e) {

((BrowseForm)FindForm()).OpenSelection.Enabled = false ;

base.OnLeave(e);

}

}
 
Andrus,

This is a REALLY bad idea. You should have this code in your Form,
which would attach to the Enter and Leave events of the ComboBox and then
enable/disable the control there. There is no need to specialize the
ComboBox class for this kind of behavior.
 
This is a REALLY bad idea. You should have this code in your Form,
which would attach to the Enter and Leave events of the ComboBox and then
enable/disable the control there. There is no need to specialize the
ComboBox class for this kind of behavior.

I create DataGridView dynamically by adding columns, including
DataGridViewComboBox columns in code.
I created my own ComBobox class and use it as DataGridView ComboBox Column
editing control.
I override Enter and Leave events in this ComBobox class as shown in code.

MSDN wrote everywhere that overriding in preferred technique for event
handling.
So I really don't understand why this is not best technique. Also using
event handlers cause the same code executed. So I see no difference how this
can help.

Andrus.
 
Back
Top