hi guys,

wondered if anyone could help please,
i have populated my combobox with the names i want, but im at a total loss on how to populate the textboxes based on my selection

im guessing its got something to do with combobox_selectedIndexChanged but i dont know how to do it,

any ideas

thanks guys

 'fills variable with the connection technology and file path of the database
        ConStr = "Provider = Microsoft.ACE.OLEDB.12.0;Data Source = C:\Users\CFA-Director\Desktop\Computer First Ade VB.net\Computer First Ade\Computer First Ade\CFA_DB.mdb"
        sql = "SELECT * FROM tbl_Customers"     'fills variable with the SQL query


        Try
            con = New OleDbConnection(ConStr)
            con.Open()
            da = New OleDbDataAdapter(sql, con)
            ds = New DataSet
            da.Fill(ds, "Customer")

            cbox_Customer.DataSource = ds.Tables("Customer")
            cbox_Customer.DisplayMember = "cust_Compnay"
            cbox_Customer.ValueMember = "cust_Company"
            cbox_Customer.SelectedIndex = -1



        Catch ex As Exception
            MessageBox.Show(ex.ToString())

        End Try

    End Sub



    Private Sub cbox_Customer_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles cbox_Customer.SelectedIndexChanged

    End Sub

This will change the text of a textbox with the text of the selection in combobox.

    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        TextBox1.Text = ComboBox1.Items(ComboBox1.SelectedIndex)
    End Sub

If you want to have different actions based on the selection a Select block would do the job:

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
    Select Case ComboBox1.Items(ComboBox1.SelectedIndex)
        Case "Test1"
            'do something
        Case "Test2"
            'do something else
    End Select
End Sub

Hi again :)
what i want to do is, from my table, my combobox selects the item, and i want to autofill the textbox with the item price, once the item is selected.

i tried the first bit of code you wrote, but having an error
Conversion from type 'DataRowView' to type 'String' is not valid.

and how would i then link that to the field i need?

many thanks

Conversion from type 'DataRowView' to type 'String' is not valid.

try something like this:

TextBox1.Text = CType(ComboBox1.Items(ComboBox1.SelectedIndex), DataRowView).Row("FieldName").ToString()

or

TextBox1.Text = CType(ComboBox1.Items(ComboBox1.SelectedIndex), DataRowView).Row(#).ToString()

where # is the zero based column index of field you want.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.