How to expand combo box on focus event?

11,944

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
Share:
11,944

Related videos on Youtube

Myth
Author by

Myth

Free Your Mind

Updated on June 04, 2022

Comments

  • Myth
    Myth almost 2 years

    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
    
    • ACP
      ACP over 14 years
      could you post some code
  • Myth
    Myth over 14 years
    Its working, but as u said, not the best soln as its showing twice. is there any better way?