views:

550

answers:

2

Hi, 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
A: 

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 :)

Madi D.
Its working, but as u said, not the best soln as its showing twice. is there any better way?
Myth
+1  A: 

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
MarcosMeli