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
LVL 1
easyworksAsked:
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.

CodeCruiserCommented:
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

cbClientId.SelectedValue=ds.Tables("Firstdb").Rows(inc).Item("TechId")
0
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.
0
YZlatCommented:
Where are you setting DataSource property of your combo box??
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

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

Open in new window

0
YZlatCommented:
or

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

0
easyworksAuthor Commented:
Yzlat are you saying I should uncheck the box for "use data bound items" and populate the combobox myself?
0
YZlatCommented:
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")
0
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?
0
YZlatCommented:
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
0
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)
0
YZlatCommented:
I believe

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

should be

cbTechId.DisplayMember = "TechId"
0
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.
        Me.InvoicesTableAdapter.Fill(Me.FirstdbDataSet.Invoices)
        'TODO: This line of code loads data into the 'FirstdbDataSet.Techs' table. You can move, or remove it, as needed.
        Me.TechsTableAdapter.Fill(Me.FirstdbDataSet.Techs)
        'TODO: This line of code loads data into the 'FirstdbDataSet.Clients' table. You can move, or remove it, as needed.
        Me.ClientsTableAdapter.Fill(Me.FirstdbDataSet.Clients)
        'TODO: This line of code loads data into the 'FirstdbDataSet.Organizations' table. You can move, or remove it, as needed.
        Me.OrganizationsTableAdapter.Fill(Me.FirstdbDataSet.Organizations)

        con.Open()

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

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

        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

        ButtonViews()

    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
            NavigateRecords()
        Else
            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
            NavigateRecords()
        Else
            MsgBox("No More Rows")
        End If
    End Sub

Open in new window

0
CodeCruiserCommented:
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.
0
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.

Both
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.
0
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")
0

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.
0
easyworksAuthor Commented:
Thanks again for your help and being taking time to explain it to me.
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.