This is the cool thing about Winforms databinding ;-). Currency managers are
what controls your binding to datasources but depending on the *path* you
take to that datasource you will end up with different currency manager
references, hence, different views into your data. This allows you to decide
whether controls should be syncronized or not to the same exact source
object. So for example if we set up controls like this:
Me.TextBox1.DataBindings.Add("Text", MyDataset, "Customers.CustomerID")
Me.TextBox2.DataBindings.Add("Text", MyDataset, "Customers.CustomerName")
You end up with both controls bound through the same Currency manager. You
can see this by taking a look at the Bindings collection:
Dim CM As CurrencyManager = DirectCast(Me.BindingContext(MyDataset,
"Customers"), CurrencyManager)
Dim bindingsCount As Integer = CM.Bindings.Count '-- returns 2
Now if we did this:
Me.TextBox1.DataBindings.Add("Text", MyDataset, "Customers.CustomerID")
Me.TextBox2.DataBindings.Add("Text", MyDataset.Tables("Customers"),
"CustomerName")
In this case you will end up with two completely separate Currency managers
because the *path* to your data source is different even though both
controls will be editing the same table, Customers.
Dim CM1 As CurrencyManager = DirectCast(Me.BindingContext(MyDataset,
"Customers"), CurrencyManager)
Dim bindingsCount1 As Integer = CM1.Bindings.Count '-- returns 1
Dim CM2 As CurrencyManager =
DirectCast(Me.BindingContext(MyDataset.Tables("Cus tomers")),
CurrencyManager)
Dim bindingsCount2 As Integer = CM2.Bindings.Count '-- returns 1
The a currency manager maintains a view of the datasource so you can easily
access the current DataView as well as the current DataRowView:
Dim dv As DataView = DirectCast(CM.List, DataView)
Dim dvr As DataRowView = DirectCast(CM.Current, DataRowView)
You can obtain currency managers for any table/path in your dataset even if
there are no control bindings set (in that case the Bindings.Count would be
0). Complex winforms databinding can take some practice, but once you get
the hang of it you can create some very cool forms.
-B
"pmcguire" <pm******@discussions.microsoft.com> wrote in message
news:8E**********************************@microsof t.com...
Can someone explain to me the difference between these two bindings?
dim b as Binding
b=New Binding(dsMyDataset.tblMyTable, "colMyColumn")
b=New Binding(dsMyDataset, "tblMyTable.colMyColumn")
They produce different behavior in my application. I know which one I
must
use, but I don't understand why.
Thanks for the help.
--
Pat