Deselecting text in ComboBox

I have ComboBoxa IsEditableset True, so I can enter TextBoxinto ComboBox. Now I want to open DropDownList, so I created for it Attached Property:

Public Shared Function GetShowDropDown(obj As DependencyObject) As Boolean
    Return obj.GetValue(IsDigitOnlyProperty)
End Function

Public Shared Sub SetShowDropDown(obj As DependencyObject, value As Boolean)
    obj.SetValue(IsDigitOnlyProperty, value)
End Sub

Public Shared ReadOnly ShowDropDownProperty As DependencyProperty = DependencyProperty.RegisterAttached("ShowDropDown", GetType(Boolean), GetType(ControlBehaviour), New UIPropertyMetadata(False, AddressOf OnShowDropDown))

Private Shared Sub OnShowDropDown(sender As Object, e As DependencyPropertyChangedEventArgs)
    Dim comboBox As ComboBox = sender
    Dim showDropDown As Boolean = e.NewValue

    If showDropDown Then
        AddHandler comboBox.PreviewKeyUp, AddressOf DoShowDropDown
    Else
        RemoveHandler comboBox.PreviewKeyUp, AddressOf DoShowDropDown
    End If
End Sub

Private Shared Sub DoShowDropDown(sender As Object, e As KeyEventArgs)
    Dim comboBox As ComboBox = sender
    If comboBox.Text.Length > 0 Then
        comboBox.IsDropDownOpen = True
    Else
        comboBox.IsDropDownOpen = False
    End If
End Sub

Whenever I type ComboBox, a DropDownList opens, but there is 1 drawback. Let me explain this as follows:

  • There are several elements (lines) in the list, of which 1 is “Test”.
  • If I type “T” in TextBox ComboBox, “est” is added after “T” to show “Test”.
  • "" TextBox . , "e", "Test" "e" TextBox ( , - .

, TextBox, , "" . , "". , .

Screen when "T" is pressed

, , - , 2- TextBox, , .


- , Enter, , DropDown.

+4
2

, SelectedIndex. -1. , -1, . , , 0.

, 5 , 6, .

, , e , ? combobox textbox, combobox , .

, 1 , . (TextChanged ..)

combobox.SelectedIndex = -1

, :

Private Sub Form1_Load () Handles Mybase.Load
       Timer1.Interval = 1
End Sub

Private Sub Timer1_Tick () Handles Timer1.Tick
       Textbox1.Text = Combobox.Text
End Sub

, , :

Combobox.Text = Textbox1.Text & a 'assuming 'a' is the text you entered later.

, !

0

IsTextSearchEnabled="True"
0

Source: https://habr.com/ru/post/1532365/


All Articles