Combobox not showing displaymember

I'm using VB 2010

My issue is I have done "use data bound items" on a combobox and have selected the parent table as the datasource. Then I set the display member to the firstname I want shown and the value member to the techId field (primarykey). Finally I set the selected value to the foreign key on the table that I'm working on, which it uses the same name and data type (techId / int). Below inc = -1 gets loaded when the form opens so when I hit the next button it just goes through the rows by adding 1.
cbTechId.DisplayMember = cbClientId.ValueMember(ds.Tables("Firstdb").Rows(inc).Item("TechId"))
txtNotes.Text = ds.Tables("Firstdb").Rows(inc).Item("Notes")

Open in new window

The combobox cbTechId does not show anything when I'm navigating through the dataset, but all the other fields that I've set not using comboboxes are like txtNotes, which is a textbox.

I'm not getting any errors.

I believe since I'm getting data for the rest of the code and everything else is working it either has to do with...
1) The way I bound the combobox or 2) The way I coded how to use the combobox
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I am confused with your question. Are you populating the combobox and its not showing values or are you setting the selected value? If later then try

easyworksAuthor Commented:
I just realized I messed up copying and pasting...
cbTechId.DisplayMember = cbTechId.ValueMember(ds.Tables("Firstdb").Rows(inc).Item("TechId"))

Open in new window

I am populating the combobox so when i navigate through the dataset it will display the techsname.
Where are you setting DataSource property of your combo box??
Starting with Angular 5

Learn the essential features and functions of the popular JavaScript framework for building mobile, desktop and web applications.

cbTechId.DisplayMember = "TechId"
txtNotes.Text = ds.Tables("Firstdb").Rows(inc).Item("Notes") 

Open in new window


With cbTechId       
        .DataSource = ds.Tables("Firstdb")
        .DisplayMember = "TechId"
        .ValueMember = "TechId"
        .SelectedIndex = 0
    End With
txtNotes.Text = ds.Tables("Firstdb").Rows(inc).Item("Notes")  

Open in new window

easyworksAuthor Commented:
Yzlat are you saying I should uncheck the box for "use data bound items" and populate the combobox myself?
if you don't want to do that, then why are you setting DisplayMember programmatically?

cbTechId.DisplayMember = cbClientId.ValueMember(ds.Tables("Firstdb").Rows(inc).Item("TechId"))
txtNotes.Text = ds.Tables("Firstdb").Rows(inc).Item("Notes")
easyworksAuthor Commented:
I'll already have a dataset I created by dropping the tables from the database into a dataset.xsd in my program. I though I could just bind this control to it and make it work? What I'm doing is not working maybe I can not go about doing it this way I don't know, but I'm really confused because I do not see how when I bind doing what you are saying that the combobox will automaticaly change as I navigate to the next record.
cbTechId.DisplayMember = cbTechId.ValueMember(ds.Tables("Firstdb").Rows(inc).Item("TechId)

Open in new window

So do I just add your code above what I'm doing?
If your combobox is bound to datatable ds.tables("Firstdb"), youcannot set its DisplayMember to a valuemember of a different combobox.

You will need to provide more information on what are you doing here and post more code
easyworksAuthor Commented:
I messed up when I was copying and pasting earlier it was not supposed to be for a different combobox.
 cbTechId.DisplayMember = cbTechId.ValueMember(ds.Tables("Firstdb").Rows(inc).Item("TechId)
I believe

cbTechId.DisplayMember = cbTechId.ValueMember(ds.Tables("Firstdb").Rows(inc).Item("TechId)

should be

cbTechId.DisplayMember = "TechId"
easyworksAuthor Commented:
Here is some more code, because I dont understand. The problem is displaying the techsname while I navigate the records.

 Public Function connection()

        con.ConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=C:\SkyDrive\VB\Projects\MyFirstDB\MyFirstDB\firstdb.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"

        Return con
    End Function

Open in new window

Imports System.Data.Linq
Imports System.Data.SqlClient
Public Class frmSecond

    Dim database As New linqfirstdbDataContext
    'connection() is grabbed from dbDataConnection to create a connection to SQL DB
    Dim con As SqlConnection = connection()
    'adapter for SQL to fill ???
    Dim da As SqlDataAdapter
    'new object dataset so we can grab the information from the database to store here?
    Dim ds As New DataSet
    'variable to say what the last row is.
    Dim MaxRows As Integer
    'Counts when navigating forwards and backwards for your database rows.
    Dim inc As Integer

    Private Sub frmSecond_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        'TODO: This line of code loads data into the 'FirstdbDataSet.Invoices' table. You can move, or remove it, as needed.
        'TODO: This line of code loads data into the 'FirstdbDataSet.Techs' table. You can move, or remove it, as needed.
        'TODO: This line of code loads data into the 'FirstdbDataSet.Clients' table. You can move, or remove it, as needed.
        'TODO: This line of code loads data into the 'FirstdbDataSet.Organizations' table. You can move, or remove it, as needed.


        Dim query = (From invo In database.Invoices
                    Select invo).ToString

        da = New SqlDataAdapter(query, con)
        da.Fill(ds, "firstdb")

        MaxRows = ds.Tables("Firstdb").Rows.Count
        inc = -1

        For Each ctl As Control In Me.Controls
            If TypeOf ctl Is ComboBox Then
                DirectCast(ctl, ComboBox).SelectedItem = Nothing
            End If
        Next ctl


    End Sub

    Private Sub NavigateRecords()

        cbOrgId.DisplayMember = cbOrgId.ValueMember(ds.Tables("Firstdb").Rows(inc).Item("OrgId"))
        cbClientId.DisplayMember = cbClientId.ValueMember(ds.Tables("Firstdb").Rows(inc).Item("ClientId"))
        cbTechId.DisplayMember = cbTechId.ValueMember(ds.Tables("Firstdb").Rows(inc).Item("TechId"))
        dtpDate.Value = ds.Tables("Firstdb").Rows(inc).Item("theDate")
        txtNotes.Text = ds.Tables("Firstdb").Rows(inc).Item("Notes")
        txtParts.Text = ds.Tables("Firstdb").Rows(inc).Item("Parts")
        txtLabor.Text = ds.Tables("Firstdb").Rows(inc).Item("Labor")
        txtMileage.Text = ds.Tables("Firstdb").Rows(inc).Item("Mileage")
        txtTotalCost.Text = ds.Tables("Firstdb").Rows(inc).Item("TotalCost")
        txtInvoiceNumber.Text = ds.Tables("Firstdb").Rows(inc).Item("InvoiceNumber")

    End Sub
Private Sub btnPrevious_Click(sender As System.Object, e As System.EventArgs) Handles btnPrevious.Click
        If inc > 0 Then
            inc = inc - 1
            MsgBox("First Record")
        End If
    End Sub

    Private Sub btnNext_Click(sender As System.Object, e As System.EventArgs) Handles btnNext.Click
        If inc <> MaxRows - 1 Then
            inc = inc + 1
            MsgBox("No More Rows")
        End If
    End Sub

Open in new window

As I said, you are using display member just to select a value which is wrong. DisplayMember is used to tell combobox which column in the datatable it should display. Is your problem loading the combobox or is your problem in selecting the correct value in a loaded combobox? If later, as I said, setting the SelectedValue should work.
easyworksAuthor Commented:
I'm trying to pull from the dataset the firstname of the tech. The table it pulls from is a int which is the Id. The Id goes to a parent table which is the PK that has a firstname of the tech.

cbTechId.SelectedValue = cbTechId.ValueMember(ds.Tables("Firstdb").Rows(inc).Item("TechId"))

Open in new window

and this
cbTechId.SelectedValue = cbTechId.SelectedValue(ds.Tables("Firstdb").Rows(inc).Item("TechId"))

Open in new window

does not display anything. If I do not use (ds.Tables("Firstdb").Rows(inc).Item("TechId")) something similar to this that allows me to change the row it is looking at then I will not be able to use the navigational button.
Jacques Bourgeois (James Burger)PresidentCommented:
You seem to completely misunderstand the use of the different properties of a data binded ComboBox.

The DisplayMember is simply the name of the field (column) that you want to show in the list. So if you want to display the FirstName field, you code should be:

cbTechId.DisplayMember = "FirstName" 'Or whatever the field is named.

The ValueMember is the name of the field (column) that you want to use in your code, most often the ID key:

cbTechId.ValueMember = "ID" 'Or whatever the field is named.

You do not set the SelectedValue. You use it to retrieve the ValueMember after the user has made a selection:

ID = CInt(cbTechID.SelectedValue)

Once you have set the DisplayMember and the ValueMember as described, the following should display the FirstName of the Tech whose ID is defined in the row pointed to by inc:

cbTechId.SelectedValue = ds.Tables("Firstdb").Rows(inc).Item("TechId")

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
easyworksAuthor Commented:
OOHHHHH. I thought when I did that all in the databind on the windows form portion I wouldn't have to specify it in the code. Thanks for being so patient with me.
easyworksAuthor Commented:
Thanks again for your help and being taking time to explain it to me.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.