Odd behavior of ComboBox when resizing

I have a problem when the ComboBox control changes it. The value of the text when resized. Here is an example of the code that I processed:


Option Explicit On  
Option Strict On

Public Class FMain  
    Private Sub FMain_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load  
        uxComboBox.DropDownStyle = ComboBoxStyle.DropDown  
        uxComboBox.AutoCompleteSource = AutoCompleteSource.ListItems  
        uxComboBox.AutoCompleteMode = AutoCompleteMode.Suggest  

        ComboTest()  
    End Sub  

    Private Sub ComboTest()  
        Dim value As String = "6"  

        uxComboBox.Text = String.Empty  
        uxComboBox.Items.Clear()  

        uxComboBox.Items.AddRange(New String() {"4 9/16", "6 9/16", "7 9/16", "8 9/16"})  

        Dim index As Integer = uxComboBox.FindStringExact(value)  
        If uxComboBox.SelectedIndex  index Then  
            uxComboBox.SelectedIndex = index  
        End If  

        If uxComboBox.SelectedIndex = -1 AndAlso _
           Not String.Equals(uxComboBox.Text, value, StringComparison.OrdinalIgnoreCase) Then  
            uxComboBox.Text = value  
        End If  

        ' unselect the text in the combobox  
        '  
        uxComboBox.Select(0, 0)  
    End Sub  
End Class  

Note that this form (FMain) has a single selection on it (uxComboBox) that attaches to the top. When I run the code, I see that the value of combobox is set to "6", as I expected. When I resize the form, the combobox gets the value "6 9/16", which I would not expect.

Does anyone know why this is happening? Any suggested workarounds?

Thanks!

Stephen

+5
source share
3 answers

, ComboBox Windows. . TabIndex = 0, CB TabIndex 1. , . . , ComboBox -, , . .

, Vista, ​​ Win7. .

+5

, ComboTest , "6", , , .,

uxComboBox.Refresh() uxComboBox.Items.AddRange.

"ComboTest", 0 uxComboBox.Index = 0.

, , , .

0

Windows 10 Visual Studio 2017. , . Hans Passant .

, , . , , , .

As a job, I removed one of the anchors and added it to the text box that was next to it. Now my combo box does not expand with the screen, instead a text field is used. I know this is not a fix, but it can help someone in a similar situation to solve the problem.

0
source

All Articles