|
-
Jul 19th, 2009, 11:45 AM
#1
Thread Starter
New Member
Fill combobox and textbox
Hi,
White this code, my ComboBox while by fill, white data frome the database.
Now i want to fill the TextBox, on basic frome the selection off the ComboBox
example,..
The ComboBox is filled white meat,
in the database is there a price attached
Whene i make a selection in the ComboBox, thane must the attached price show up in the TextBox.
My code works for de ComboBox, but not for the TextBox.
Can you help my.
sorry for the bad englisch
gr,
Steve
Code:
Try
Dim strSQL As String = "Select * From Grondstof"
Dim strConnectionString As String = My.Settings.grondstoffenConnectionString()
Dim objConnection As New SqlConnection(strConnectionString)
Dim objCommand As New SqlCommand(strSQL, objConnection)
objCommand.Connection.Open()
Dim objDataReader As SqlDataReader = objCommand.ExecuteReader(CommandBehavior.CloseConnection)
ComboBox1.Items.Clear()
ComboBox2.Items.Clear()
ComboBox3.Items.Clear()
ComboBox4.Items.Clear()
ComboBox5.Items.Clear()
ComboBox1.Items.Insert(0, "maak keuze")
ComboBox2.Items.Insert(0, "maak keuze")
ComboBox3.Items.Insert(0, "maak keuze")
ComboBox4.Items.Insert(0, "maak keuze")
ComboBox5.Items.Insert(0, "maak keuze")
While objDataReader.Read
Debug.Print(objDataReader("Vleessoort").ToString)
ComboBox1.Items.Add(objDataReader("Vleessoort").ToString)
ComboBox2.Items.Add(objDataReader("Vleessoort").ToString)
ComboBox3.Items.Add(objDataReader("Vleessoort").ToString)
ComboBox4.Items.Add(objDataReader("Vleessoort").ToString)
ComboBox5.Items.Add(objDataReader("Vleessoort").ToString)
End While
Me.ComboBox1.SelectedIndex = 0
Me.ComboBox2.SelectedIndex = 0
Me.ComboBox3.SelectedIndex = 0
Me.ComboBox4.SelectedIndex = 0
Me.ComboBox5.SelectedIndex = 0
Dim dt As New DataTable 'test
Dim da As SqlDataAdapter 'test
da.Fill(dt) 'test
ComboBox1.DataSource = dt 'test
ComboBox1.ValueMember = "ID" 'test
ComboBox1.DisplayMember = "Prijs" 'test
txtPrijs = DirectCast(Me.ComboBox1.SelectedValue, DataRowView).Item("ID") 'test optie Nr1
txtPrijs.DataBindings.Add("Prijs", dt, "ID") 'test optie Nr2
objDataReader.Close()
Catch ex As Exception
MessageBox.Show("Fout opgetreden: " & ex.Message.ToString)
Finally
End Try
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|