0
votes

I have a very weird issue. I have a ComboBox control on a form. It has a DataSource of DataTable. It has both DisplayMember and ValueMember set. I have debugged and set break points, the very last bit of code confirms that the data IS THERE. I have used the DataTable visualizer and rows are displayed with the values I want. I have run commands in the Immediate window while debugging to check the count of items, confirm the DisplayMember etc all is okay there. The empty white space that appears in the ComboBox changes size as per my selection, but no text is displayed? Very very strange. I have set up another ComboBox in exactly the same way and it works fine. IT SHOULD WORK! The back end tells me that it is working, but it just simply isn't displaying. Any ideas? .NET 4, VB.NET, WinForms. Anyone have this issue/solution?

Here's the code (it never errors either).

    Public Sub RefreshContacts(ByVal CustomerKey As Integer)
    Using tContactsTa As New dbQMSTableAdapters.tContactsTableAdapter, tContactsDt As New dbQMS.tContactsDataTable
        Try
            tContactsTa.FillBasicByCustomerKey(tContactsDt, CustomerKey)
            cmbCncts.BeginUpdate()
            With cmbCncts
                .DataSource = tContactsDt
                .ValueMember = "fContactKey"
                .DisplayMember = "fContactName"
            End With
            cmbCncts.EndUpdate()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        Finally
        End Try
    End Using
End Sub

As I said before, I have debugged and looked at the DataTable visualiser, the data is there. When I run ? cmbCncts.Items.Count it feedsback the correct value. I also check the DisplayMember and the ValueMember properties which are all correct.

1
is datamode property of combobox set to normal?akhil kumar
There is not a DataMode property. There is DrawMode and yes it is set to NormalBilly Brown
I accidentally got here because i had the same issue. After investigating the problem is in using part. put it outsideprogramer Anel

1 Answers

0
votes

Okay so I solved the issue (I'm still annoyed that I can't work out why it didn't work). I'm doing it differently now so it works how I want it to. Even still, the original way should of worked as other ComboBox controls I have work in exactly the same way. New code:

        Using tContactsTa As New dbQMSTableAdapters.tContactsTableAdapter, tContactsDt As New dbQMS.tContactsDataTable
        Try
            tContactsTa.FillBasicByCustomerKey(tContactsDt, CustomerKey)
            cmbCncts.BeginUpdate()
            cmbCncts.Items.Clear()
            cmbCncts.ValueMember = "fContactKey"
            cmbCncts.DisplayMember = "fContactName"
            For Each rw As dbQMS.tContactsRow In tContactsDt
                cmbCncts.Items.Add(rw)
            Next
            'With cmbCncts
            '    .DataSource = tContactsDt
            '    .ValueMember = "fContactKey"
            '    .DisplayMember = "fContactName"
            'End With
            cmbCncts.EndUpdate()
            If cmbCncts.Items.Count > 0 Then
                cmbCncts.SelectedIndex = 0
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        Finally
        End Try
    End Using