How to Complex/simple bind a combobox in vb.net

I would like to know:

How to Complex/simple bind a combobox in vb.net ? what does it mean? in which circumstance it is used?

a simple and clear example will be appreciated.

thanks
jskfanAsked:
Who is Participating?
 
NicoLaanConnect With a Mentor Commented:
Ah, now I remember (now I see it).

Simple binding works like this:

ControlName.DataBindings.Add(New Binding("name of property from control to bind", "DataTable", "DataField"))

i.e.

Combobox1.DataBindings.Add(New Binding("SelectedValue", "SalesTable", "CustId"))

Now any value you select in the combobox will be changed in the SalesTable.CustId.
If you want it to respond to the text edited in the combobox you should use SelectedText I think.

So for simple binding, don't use the datasource property, that's only used in the complex binding.

Of course for a combobox you'll mostly want to use both complex and simple binding. Complex to show all CustId's from CustTable in the list, simple to get the selected value in the SalesTable.

In my examples I assumed SalesTable to hold something like this: CustId, ProductId, Date of sale, amount of sale. I only describe the part for the CustId. But I think you might've understood all this already.
0
 
MilanKMConnect With a Mentor Commented:
Data binding is divided into two categories: simple and complex binding. Simple binding means low level binding, where as complex binding means high level binding.

Simple data binding means a single value of a data source is bound to a control. Any property of a component can be bound to any value of a data source. For example you can bind the Text property of a TextBox to a column of a table.
http://www.exforsys.com/content/view/1547/350/

Complex data binding means a control is bound to a data source and examines and handles the structure by itsself. Examples for this category are the DataGrid and the ComboBox control. See more:~ http://www.exforsys.com/content/view/1548/350/

Aslo see the link below...
http://www.codeproject.com/vb/net/databindingconcepts.asp

Thanks
MilanKM
0
 
jskfanAuthor Commented:
Can you explain the difference in a simple way please ? it's not clear on the link.

thanks
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
YoungBonziConnect With a Mentor Commented:
Simple Data Binding
Simple data binding means binding a single value within the data model to a single property of a control. For example, binding TextBox1.Text to Customer.Name.

Complex Data Binding
Complex data binding means binding a control to a collection (rather than binding a control to a single item within the collection).

http://www.dotnetjunkies.com/quickstart/winforms/doc/WinFormsData.aspx


============

In the real world, the biggest difference is that simple binding can only show one element at a time, but complex binding can fill an entire grid.

To understand for your self build this tutorial on your own, you'll see the difference:

simple: http://blogs.msdn.com/ariroth/archive/2004/12/17/323807.aspx
complex: http://blogs.msdn.com/ariroth/archive/2005/01/21/358478.aspx
0
 
NicoLaanConnect With a Mentor Commented:
Example:

Combobox used to identify who (from custTable) bought an item (data stored in salesTable):

You'd (complex) bind the customer names to the various items in the combobox (the list you see when you click it).
Properties:
 DataSource (custTable)
 DisplayMember (custName)
 ValueMember (custId)

You'd simple bind the selected value to the SalesTable.
Properties:
 SelectedValue (will hold the selected custId)

Or using other types of simple binding:
 SelectedIndex
 SelectedItem
 SelectedText
0
 
jskfanAuthor Commented:
I have tried both simple and complex databinding to 2 comboboxes and they show the same thing. the whole list of customers names

I used for one combobox:
DataSource
DisplayMember
ValueMember


then the other combobox
DataSource
SelectedValue

0
 
jskfanAuthor Commented:
I might haven't understood in which situation I should use simple and in which I should use complex.
0
 
NicoLaanConnect With a Mentor Commented:
Simple binds to 1 record, i.e. a textbox.
Complex binds to all rows in the table, i.e. the list of items in a combobox or a datagrid.
The selected value in the combobox would be bound with simple binding, the list of items with complex binding.

I forgot to mention some property I think, will look from work tomorrow (12 hours from now) if I can.
0
 
jskfanAuthor Commented:
I will try it later and get back with you
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.