473,320 Members | 1,572 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Databinding

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
Nov 21 '05 #1
4 2153
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

Nov 21 '05 #2
Yes, I agree that the ability to create multiple currency managers against
the same DataSource is a powerful tool (I am only now getting into it in my
application; and the doors it opens are very interesting); however, this
implementation smells a little like an unintended feature. As I read your
response, your ability to create these independent CurrencyManagers is
limited by the number of unique paths to the same data element you can come
up with. It seems like just an explicit declaration of "New
CurrencyManager..." would be better.

As I said, I'm just now getting into this, so maybe I'm just not fully
appreciating the situation yet.

Thanks, though, for the explanation.

Pat

"Beth Massi [Architect MVP]" wrote:
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


Nov 21 '05 #3
I didn't mention it in my first post, but you can create as many cm's to the
datasources as you want by creating different DataView references and bind
to them instead. So it isn't limited.

Dim dv1 As New DataView(myDataSet.Table1)
Dim dv2 As New DataView(myDataSet.Table1)
Dim dv3 As New DataView(myDataSet.Table1)
Dim dv4 As New DataView(myDataSet.Table1)
Dim dv5 As New DataView(myDataSet.Table1)
'-- These will be different currency managers
Dim cm1 As CurrencyManager = DirectCast(Me.BindingContext(dv1),
CurrencyManager)
Dim cm2 As CurrencyManager = DirectCast(Me.BindingContext(dv2),
CurrencyManager)
Dim cm3 As CurrencyManager = DirectCast(Me.BindingContext(dv3),
CurrencyManager)
Dim cm4 As CurrencyManager = DirectCast(Me.BindingContext(dv4),
CurrencyManager)
Dim cm5 As CurrencyManager = DirectCast(Me.BindingContext(dv5),
CurrencyManager)

"pmcguire" <pm******@discussions.microsoft.com> wrote in message
news:97**********************************@microsof t.com...
Yes, I agree that the ability to create multiple currency managers against
the same DataSource is a powerful tool (I am only now getting into it in
my
application; and the doors it opens are very interesting); however, this
implementation smells a little like an unintended feature. As I read your
response, your ability to create these independent CurrencyManagers is
limited by the number of unique paths to the same data element you can
come
up with. It seems like just an explicit declaration of "New
CurrencyManager..." would be better.

As I said, I'm just now getting into this, so maybe I'm just not fully
appreciating the situation yet.

Thanks, though, for the explanation.

Pat

"Beth Massi [Architect MVP]" wrote:
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


Nov 21 '05 #4
Pat,

The trouble is that with seeing this code I don't know as I earlier asked
what goes wrong and as well not what you want to achieve.

The second is that it is about a strongly typed dataset, what I never use
and therefore for me a little bit extra difficult to understand what goes
wrong.

Therefore tell me first a little bit what you want.

Probably you get no answer more today, I have to go however maybe somebody
else sees it than..

Cor
Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Kevin Swanson | last post by:
I'm writing what should be a very simple app against an Oracle database. The app has a number of user controls, any one of which is loaded into a main display page using the loadControl method,...
3
by: John Bailey | last post by:
When I first built a few web pages in ASP .Net 2.0, I thought it was great. The formview and detailview contorls would automatically layout the controls for you, the update methods were...
4
by: Nathan Sokalski | last post by:
I have two databinding expressions (the first & last names from a DB) that I want to assign to the text property of a Label so that the result is LASTNAME,FIRSTNAME. At the moment, I have the...
9
by: Dennis | last post by:
I have tried using Databinding for my application but always seem to find it very restrictive (maybe I don't completely understand it enough). I always seem to find it much easier to display a...
8
by: GaryDean | last post by:
We have been noticing that questions on vs.2005/2.0 don't appear to get much in answers so I'm reposting some questions posted by some of the programmers here in our organization that never got...
0
by: Wayne Sepega | last post by:
I have the following Object DataSource <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetCustomer" TypeName="Customers" DataObjectTypeName="Customer"...
9
by: J055 | last post by:
Hi I have a very simple configuration of the GridView with paging and sorting. When I do a postback the DataBinding event fires twice - in both the ProcessPostData and PreRender stages of the...
1
by: CorporateCoder | last post by:
Hi, I am trying to bind the selected value of a databound dropdown box in a databound gridview control to the value being displayed in the template column the dropdown box has been added to. ...
8
by: Dirk | last post by:
Hello, I have a problem to use databinding with my business layer classes. My data class does not have simple properties (string, int or datetime), instead, all my properties are objects of the...
1
by: =?Utf-8?B?QWxoYW1icmEgRWlkb3MgS2lxdWVuZXQ=?= | last post by:
Hello to all, I want to know if DataBinding in asp.net 2,0 is better than to fill up the values of the controls of the following form: this.miControlTextBox.Text = valorParaControlTextbox; ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.