2 Replies - 3143 Views - Last Post: 17 August 2012 - 10:07 AM Rate Topic: -----

#1 Easy-Works  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 17-August 12

Combobox not showing displaymember

Posted 17 August 2012 - 06:37 AM

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")


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

Is This A Good Question/Topic? 0
  • +

Replies To: Combobox not showing displaymember

#2 rgfirefly24  Icon User is offline

  • D.I.C Lover
  • member icon


Reputation: 262
  • View blog
  • Posts: 1,467
  • Joined: 07-April 08

Re: Combobox not showing displaymember

Posted 17 August 2012 - 08:38 AM

what you want to do is set DisplayMember and ValueMember equal to the column header you want displayed. I.E:

cbTechId.DisplayMember = "FirstName"
cbTechId.ValueMember = "TechId"


Was This Post Helpful? 1
  • +
  • -

#3 Easy-Works  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 17-August 12

Re: Combobox not showing displaymember

Posted 17 August 2012 - 10:07 AM

The problem is displaying any information in the comboboxes while I navigate the records. Could part of my problem be not joining the tables in my LINQ query?

 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



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



Was This Post Helpful? 0
  • +
  • -

Page 1 of 1