I'm having trouble getting some data from a combobox. I have a series of comboboxes that populate as you make selections from the boxes. Each combobox is using data that is pulled from a SQL database into a dataset. This all works.

When I get to the last box, I want to view one column from this dataset, but have the selected value be from another column. For some reason, it will not select this other data. In the code sample, after the user goes through the procedure to select everything, the click a button. For test purpose, this button pops up a msgbox with the data that is desired. Right now, the data desired is NOT appearing. Instead I just receive a "-1". Anyone know anything about this?

Public main As frmDashboard
    Public view As frmTrainingView
    Dim strID As String

    Private Sub frmSelect_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim tblmodels As DataSet1.docHeaderDataTable
        tblmodels = Me.DocHeaderTableAdapter.GetAllModels
        Me.ComboBox1.DataSource = tblmodels
        Me.ComboBox1.DisplayMember = "Model"
        Me.ComboBox1.ValueMember = "Model"
    End Sub
    Private Sub Model_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        Dim tblparts As DataSet1.docHeaderDataTable
        tblparts = Me.DocHeaderTableAdapter.GetPartByModel(Convert.ToString(ComboBox1.SelectedValue))
        Me.ComboBox2.DataSource = tblparts
        Me.ComboBox2.DisplayMember = "Part"
        Me.ComboBox2.ValueMember = "Part"
    End Sub
    Private Sub Part_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged
        Dim tblman As DataSet1.docHeaderDataTable
        tblman = Me.DocHeaderTableAdapter.Getmanning(Convert.ToString(ComboBox1.SelectedValue), Convert.ToString(ComboBox2.SelectedValue))
        Me.ComboBox3.DataSource = tblman
        Me.ComboBox3.DisplayMember = "Manning"
        Me.ComboBox3.ValueMember = "Manning"
    End Sub
    Private Sub Manning_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox3.SelectedIndexChanged
        Dim tblpos As DataSet1.docHeaderDataTable
        tblpos = Me.DocHeaderTableAdapter.GetPos(Convert.ToString(ComboBox1.SelectedValue), Convert.ToString(ComboBox2.SelectedValue), Convert.ToString(ComboBox3.SelectedValue))
        Me.ComboBox4.DataSource = tblpos
        Me.ComboBox4.DisplayMember = "Position"
        Me.ComboBox4.ValueMember = "Position"
    End Sub
    Private Sub Position_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox4.SelectedIndexChanged
        Dim tbldoc As DataSet1.docHeaderDataTable
        tbldoc = Me.DocHeaderTableAdapter.GetDoc(Convert.ToString(ComboBox1.SelectedValue), Convert.ToString(ComboBox2.SelectedValue), Convert.ToString(ComboBox3.SelectedValue), Convert.ToString(ComboBox4.SelectedValue))
        Me.ComboBox5.DataSource = tbldoc
        Me.ComboBox5.DisplayMember = "docType"
        Me.ComboBox5.ValueMember = "docID"
    End Sub
    Private Sub btnBegin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        strID = Convert.ToString(ComboBox5.SelectedItem)
    End Sub

To make sure I uderstand.

The user first selects a model.
This then fills up combobox2 with parts

The user then selects a part which then fills combobox3 with "manning" data?
The user then selects a "manning" which then fills combobox 4 with "position" data.
The user then selects a position which should then fill combobox5 with DocTypes.

The user is supposed to then select a doc type from the list in combobox5 and click a "begin" button.

My guess is that there either isn't any data in combobox5, or the user isn't selecting an item and there isn't a default selection set.

I would add a line of code for the last box so that if the combo boxes item count is > 0 then set the selected index = 0.

-1 is the selected index if no items are selected.

You are correct about how this works. However, I have found the problem. And since finding the problem, and reading this, I have taken into consideration your input, and this is what I have:

Private Sub btnBegin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        If Me.ComboBox5.SelectedValue = Nothing Then
            Me.main.strdoc = ComboBox5.SelectedValue.ToString
        End If
    End Sub

I found that .SelectedItem did not work, but .SelectedValue did.
I hope you like the message box!

Thanks for your help!

I should have seen that with the "selectedItem". DOH!

Glad you figured it out.

That msg should really get their attention... unless all your messages are uppercase. ô¿ô