I have this form Customer which is designed with labels, textboxes and comboboxes. I want to populate them by way of databinding. How can i do this??
Printable View
I have this form Customer which is designed with labels, textboxes and comboboxes. I want to populate them by way of databinding. How can i do this??
If you have defined a datasource at design time, you can specify the property you want to bind and populate from that datasource.
Since you have not provided much information, I'll just explain with illustration. I assume that you have created the dataset & binding source at design time and have a textbox you want to bind to this dataset.
So open the properties of this textbox, and expand the DataBindings node. You will see all the properties that can be bound. Chooose the property you want to bind. For textbox, you would bind the Text property to display. Click the combo dropdown beside it and choose the field to bind it to. (see attached screenshot.)
Attachment 73879
Just in case you are creating your datasource from code, you need to create the databindings there.
For e.g. something like this should work:
vb.net Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load TextBox1.DataBindings.Add "Text", TheDataSource, TheDataMember) End Sub
Thanks for your prompt reply Pradeep.
I have binded the textbox to the datasource as you described. But after launching the application the data is not showing up in the textbox. For eg. on startup i want to show details of Client_ID no:1. How can i do this?
Lux.
Are you sure you have populated your datasource before you are expecting it to be shown there in the controls?
Yes, i have.
Are you databinding at design time or from code?
You might need to call the DataBind method after you have set the bindings:
vb Code:
TextBox1.DataBindings.Add "Text", TheDataSource, TheDataMember) TextBox1.DataBind()
oki got it!!! thanks.. and what do i have to do when i need to update the dataset??
call DataAdapter.Update method