Click here to Skip to main content
15,915,093 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hey there.
im trying to get data from a table connected through access into my combobox. i'll key in the id first then click get then 5 values from that id will have to appear at the 5 combobox under. but my code seem not working. can anybody help me to show which part did i made wrong and its solution? thank you very much for ur help :D

VB
Public Sub Get_Data()
        con.Open()

        Dim dt As New DataTable("table1")
        Dim rs As New OleDb.OleDbDataAdapter("select * from table1 where id= '" & TextBox1.Text & "' ", con)
        rs.Fill(dt)

        DataGridView1.DataSource = dt
        DataGridView1.Refresh()

        rs.Dispose()
        con.Close()

        If Val(Label7.Text) = 1 Then
            Dim i As Integer
            i = DataGridView1.CurrentRow.Index

            ComboBox1.Text = DataGridView1.Item(1, i).Value.ToString()
            ComboBox2.Text = DataGridView1.Item(2, i).Value.ToString()
            ComboBox3.Text = DataGridView1.Item(3, i).Value.ToString()
            ComboBox4.Text = DataGridView1.Item(4, i).Value.ToString()
            ComboBox5.Text = DataGridView1.Item(5, i).Value.ToString()

        End If

    End Sub



VB
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button4.Click
        Get_Data()

    End Sub
Posted

1 solution

Use Combobox.Items.add intead of assigning it to .Text.

VB
ComboBox1.Items.clear
ComboBox1.Items.add( DataGridView1.Item(1, i).Value.ToString)
ComboBox1.Items.add( DataGridView1.Item(2, i).Value.ToString)
ComboBox1.Items.add( DataGridView1.Item(3, i).Value.ToString)
ComboBox1.Items.add( DataGridView1.Item(4, i).Value.ToString)
ComboBox1.Items.add( DataGridView1.Item(5, i).Value.ToString)
 
Share this answer
 
Comments
fahmijaafar 29-Jun-15 3:40am    
ive tried the solution u provided but still the data doesn't appear on the combobox. :(
Ralf Meier 29-Jun-15 5:44am    
If you set a Breakpoint into your Script/Method (GetData) - is there data displayed for the SelectedItem of the DGV ?
Ralf Meier 29-Jun-15 6:55am    
Is "DataGridView1.Item(1, i).Value" the right access to the element you wish ? Perhaps you should use "DataGridView1.row(i).column(1).Value" ...
fahmijaafar 29-Jun-15 10:37am    
luckily ive found the solution by just adding Me. infront of the combobox1. :D
btw thanks for ur help Mr. Ralf Meier.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900