Fill a textbox from a table.

johmolan

Well-known member
Joined
Oct 11, 2008
Messages
129
Programming Experience
Beginner
I have a Richtextbox in my form and a table called Xtra in an accessdatabase.

In the database there is a column called Notes and a column called ID.

I made a combobox to choose the ID, then I want to update the textbox with the text from the cell in column Notes.

I Tried:

RichTextBox1.Text= Kalkyletabeller1DataSet.Xtra where ID = ComboBox1.Text

But no luck.

Anyone know what I am doing wrong and can give me hint?
 
Last edited:
You should use data-binding, then there's no need for code at all. Add a BindingSource to your form and once you've populated your DataTable:
VB.NET:
Me.BindingSource1.DataSource = Kalkyletabeller1DataSet.Xtra

Me.ComboBox1.DisplayMember = "ID"
Me.ComboBox1.DataSource = Me.BindingSource1

Me.RichTextBox1.DataBindings.Add("Text", Me.BindingSource1, "Notes")
If your notes contain RTF markup then you should bind to the Rtf property insteda of the Text property. If your notes don't contain RTF markup then I don't see why you'd use a RichTextBox over a regular TextBox.

Note that you can also set up that binding in the designer if your DataSet was also added in the designer. That way there's no code at all, even for binding.
 
Back
Top