I think I found a bug in the combobox control. I can get the combobox.selectedvalue to be different from the value shown in the combobox.

Try to run the code and see for your self how it acts. When running the form I have included a description of how to reproduce the bug.

Just want a confirmation from other before sending it to Microsoft.

Public Class Form1

    Public WithEvents ComboBox1 As System.Windows.Forms.ComboBox
    Public WithEvents ComboBox2 As System.Windows.Forms.ComboBox
    Public WithEvents Label1 As System.Windows.Forms.Label
    Public WithEvents Label2 As System.Windows.Forms.Label
    Public WithEvents Label3 As System.Windows.Forms.Label
    Public WithEvents lbl_ValueOfUserObjectCombobox As System.Windows.Forms.Label
    Public WithEvents lbl_ValueOfStringArrayCombobox As System.Windows.Forms.Label
    Public WithEvents Label6 As System.Windows.Forms.Label
    Public WithEvents Label4 As System.Windows.Forms.Label

    Public Sub New()

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        Me.ComboBox1 = New System.Windows.Forms.ComboBox
        Me.ComboBox2 = New System.Windows.Forms.ComboBox
        Me.Label1 = New System.Windows.Forms.Label
        Me.Label2 = New System.Windows.Forms.Label
        Me.Label3 = New System.Windows.Forms.Label
        Me.lbl_ValueOfUserObjectCombobox = New System.Windows.Forms.Label
        Me.lbl_ValueOfStringArrayCombobox = New System.Windows.Forms.Label
        Me.Label6 = New System.Windows.Forms.Label
        Me.Label4 = New System.Windows.Forms.Label
        Me.SuspendLayout()
        '
        'ComboBox1
        '
        Me.ComboBox1.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Suggest
        Me.ComboBox1.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems
        Me.ComboBox1.Location = New System.Drawing.Point(64, 96)
        Me.ComboBox1.Name = "ComboBox1"
        Me.ComboBox1.Size = New System.Drawing.Size(121, 21)
        Me.ComboBox1.TabIndex = 1
        '
        'ComboBox2
        '
        Me.ComboBox2.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Suggest
        Me.ComboBox2.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems
        Me.ComboBox2.Location = New System.Drawing.Point(312, 96)
        Me.ComboBox2.Name = "ComboBox2"
        Me.ComboBox2.Size = New System.Drawing.Size(121, 21)
        Me.ComboBox2.TabIndex = 3
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(64, 40)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(152, 56)
        Me.Label1.TabIndex = 0
        Me.Label1.Text = "Combobox with array of userObjects as datasource and valuemember and displaymembe" & _
            "r set!"
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(312, 56)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(152, 40)
        Me.Label2.TabIndex = 2
        Me.Label2.Text = "Combobox with array of string as datasource"
        '
        'Label3
        '
        Me.Label3.AutoSize = True
        Me.Label3.Location = New System.Drawing.Point(64, 136)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(122, 13)
        Me.Label3.TabIndex = 4
        Me.Label3.Text = "Value when tabbing out:"
        '
        'lbl_ValueOfUserObjectCombobox
        '
        Me.lbl_ValueOfUserObjectCombobox.AutoSize = True
        Me.lbl_ValueOfUserObjectCombobox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.lbl_ValueOfUserObjectCombobox.Location = New System.Drawing.Point(64, 152)
        Me.lbl_ValueOfUserObjectCombobox.Name = "lbl_ValueOfUserObjectCombobox"
        Me.lbl_ValueOfUserObjectCombobox.Size = New System.Drawing.Size(2, 15)
        Me.lbl_ValueOfUserObjectCombobox.TabIndex = 5
        '
        'lbl_ValueOfStringArrayCombobox
        '
        Me.lbl_ValueOfStringArrayCombobox.AutoSize = True
        Me.lbl_ValueOfStringArrayCombobox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.lbl_ValueOfStringArrayCombobox.Location = New System.Drawing.Point(312, 152)
        Me.lbl_ValueOfStringArrayCombobox.Name = "lbl_ValueOfStringArrayCombobox"
        Me.lbl_ValueOfStringArrayCombobox.Size = New System.Drawing.Size(2, 15)
        Me.lbl_ValueOfStringArrayCombobox.TabIndex = 7
        '
        'Label6
        '
        Me.Label6.AutoSize = True
        Me.Label6.Location = New System.Drawing.Point(312, 136)
        Me.Label6.Name = "Label6"
        Me.Label6.Size = New System.Drawing.Size(122, 13)
        Me.Label6.TabIndex = 6
        Me.Label6.Text = "Value when tabbing out:"
        '
        'Label4
        '
        Me.Label4.AutoSize = True
        Me.Label4.Location = New System.Drawing.Point(64, 208)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(640, 182)
        Me.Label4.TabIndex = 8
        Me.Label4.Text = "Select 'a' in both comboboxes." & vbNewLine & "Then do the following:" & vbNewLine & vbNewLine & "1: Click the drop down arrow on the combobox with the mouse" & vbNewLine & "2: Use the mouse to put the cursor over the list item 'b' so that it is highlighted BUT DO NOT CLICK ON THE HIGHLIGHTED VALUE." & vbNewLine & "3: While the highlight is on 'b', press the tab key." & vbNewLine & vbNewLine & "You will now see a bug in the combobox to the left:" & vbNewLine & "'a' is still the value shown but 'b' is returned as answer if I ask of the text/selectedValue/etc. of the combobox." & vbNewLine & vbNewLine & "If you set the focus back to the combobox again (which still shows 'a') and then tab out normally -> What happens on your computer?" & vbNewLine & "'a' is still shown but is 'a' or 'b' answered as selectedValue? I have seen examples of both! (.net framework 3.5 and vs.net 2008)" & vbNewLine & vbNewLine & "On the combobox to the right the behaviour is NOT like that!"
        '
        'Form2
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(800, 396)
        Me.Controls.Add(Me.lbl_ValueOfStringArrayCombobox)
        Me.Controls.Add(Me.Label4)
        Me.Controls.Add(Me.Label6)
        Me.Controls.Add(Me.lbl_ValueOfUserObjectCombobox)
        Me.Controls.Add(Me.Label3)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.ComboBox2)
        Me.Controls.Add(Me.ComboBox1)
        Me.Name = "Form2"
        Me.Text = "Form2"
        Me.ResumeLayout(False)
        Me.PerformLayout()


        Dim lStrings As String()
        lStrings = New String() {"a", "b"}
        Me.ComboBox2.DataSource = lStrings

        Dim lDatasource_TestObjects As Test()
        lDatasource_TestObjects = New Test() {New Test(1, "a"), New Test(2, "b")}


        Me.ComboBox1.DataSource = lDatasource_TestObjects
        Me.ComboBox1.DisplayMember = "Description"
        Me.ComboBox1.ValueMember = "Description"


    End Sub

    Private Sub ComboBox1_Validated(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.Validated
        With ComboBox1
            Debug.Print("UserObjectArray_Validated: Text = " & .Text & ", SelectedIndex = " & .SelectedIndex & ", SelectedText = " & .SelectedText & ", SelectedValue = " & .SelectedValue & ", SelectedItem = " & CType(.SelectedItem, Test).Description)
            Me.lbl_ValueOfUserObjectCombobox.Text = .Text
        End With
    End Sub

    Private Sub ComboBox2_Validated(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.Validated
        With ComboBox2
            Debug.Print("StringArray_Validated    : Text = " & .Text & ", SelectedIndex = " & .SelectedIndex & ", SelectedText = " & .SelectedText & ", SelectedValue = " & .SelectedValue & ", SelectedItem = " & .SelectedItem.ToString)
            Me.lbl_ValueOfStringArrayCombobox.Text = .Text
        End With
    End Sub

    Public Class Test
        Private mDBValue As Int32
        Private mDescription As String
        Public Sub New(ByVal value As Int32, ByVal description As String)
            Me.DBValue = value
            Me.Description = description
        End Sub

        Public Property DBValue() As Int32
            Get
                Return mDBValue
            End Get
            Set(ByVal value As Int32)
                mDBValue = value
            End Set
        End Property

        Public Property Description() As String
            Get
                Return mDescription
            End Get
            Set(ByVal value As String)
                mDescription = value
            End Set
        End Property
    End Class

End Class

Same thing happens (using vb 2010), i gues it might be a bug,

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.