3

I want to automatically expand Combo box on focus event. I have set the Droppeddown = True in gotfocus event, but this has a side effect. When click event gets fired, it expands dropdown and closes immediately. How can I avoid it?

Here is Code:

Private Sub cmbElectLoadPS_gotfocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmbElectLoadPS.GotFocus
       cmbElectLoadPS.DroppedDown = True
End Sub
1
  • could you post some code
    – ACP
    Dec 17, 2009 at 10:01

4 Answers 4

4

What about check if already DroppedDown ?

Private Sub cmbElectLoadPS_gotfocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmbElectLoadPS.GotFocus
       if Not cmbElectLoadPS.DroppedDown Then
          cmbElectLoadPS.DroppedDown = True
       End If
End Sub

If u need this behavior for all your combo controls is better to create your own implementation

Pulic Class CustomComboBox
     Inherits ComboBox

    Protected Overrides Sub OnEnter(ByVal e As System.EventArgs)
           if Not DroppedDown Then
              DroppedDown = True
           End If
    End Sub

End Class
0
0

Oh .. add the same value to ComboBox on Mouseup event.. it would do the trick for u :) sthing like :

    private void comboBox1_Enter(object sender, EventArgs e)
    {

        comboBox1.DroppedDown = true;
    }

    private void comboBox1_MouseUp(object sender, MouseEventArgs e)
    {
        comboBox1.DroppedDown = true;
    }

Not your best solution.. but it would do the trick :)

1
  • Its working, but as u said, not the best soln as its showing twice. is there any better way?
    – Myth
    Dec 21, 2009 at 6:54
0

Create a timer called tmrDropDown (you should create a timer for each ComboBox) and leave its default properties. Add this code:

Private Sub cmbBox_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmbBox.GotFocus
    tmrDropDown.Enabled = True
End Sub

And

Private Sub tmrDropDown_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrDropDown.Tick
    cmbBox.DroppedDown = True
    tmrDropDown.Enabled = False
End Sub
0

To implement this features for multiple combobox controls, rather than inheriting the combobox as a new custom control, I'd propose this simple solution:

Private Sub AutoDropDownCombobox_Enter(sender As Object, e As EventArgs) Handles _
    cboControl1.Enter, cboControl2.Enter ' register additional events here
    If Not CType(sender, ComboBox).DroppedDown Then
        CType(sender, ComboBox).DroppedDown = True
    End If
End Sub

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.