471,570 Members | 1,671 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Uninitialized data-binding

Hello
I've created a form with 2 listboxes. Both have data-binding. First one
is "normal", 1:1 view of table. Second is filled using parameter from
the first one.

this.xxxTableAdapter.Fill(this.mainDataSet.XXX,
(int)this.BindingContext[yyyBindingSource, "id"].Current);

When I do it in Form_Load() it shows first listbox with element with
"id" of value 2 selected, but this.BindingContext[yyyBindingSource,
"id"].Current == 1. When I do the same thing in
yyyBindingSource_CurrentChanged later it gives expected results.
How can I fix the behaviour just after window creation? I guess it's
connected with listbox not initialized properly with new data between
those two .Fill() calls.

Feb 4 '06 #1
2 1699
Message passed unnoticed. So once more:
After some tests i found out that in function
setsBindingSource_CurrentChanged() value:
(DataRowView)setsBindingSource.Current)["id"]
is correct, but
BindingContext[setsBindingSource, "id"].Current
shows the previous value, not the new one. Is that normal? Is there any
other/better way to get that "id"?

Feb 5 '06 #2
Hi,

"Viraptor" <vi******@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Message passed unnoticed. So once more:
After some tests i found out that in function
setsBindingSource_CurrentChanged() value:
(DataRowView)setsBindingSource.Current)["id"]
is correct, but
That's the correct way. A BindingSource owns a CurrencyManager which manages
a list binding and current position.

Calling:
setsBindingSource.Current

results in:
setsBindingSource.CurrencyManager.Current.
BindingContext[setsBindingSource, "id"].Current
shows the previous value, not the new one. Is that normal?
This is very confusing. In NET1.1 there were no BindingSource's, there was
a CurrencyManager and BindingContext. BindingContext used to own
CurrencyManagers.

But in NET2.0 a BindingSource directly owns a single CurrencyManager, so if
you pass a BindingSource to the indexer of any BindingContext to request a
CurrencyManager it will relay the request back to the BindingSource passed
in:

If you pass setBindingsSource to the indexer of *any* BindingContext:
BindingContext[setBindingsSource , "id"]

it will return:
setBindingsSource.GetRelatedCurrencyManager("id")

if DataMember is empty then it will return:
setBindingSource.CurrencyManager

but since DataMember isn't empty it willl create a new BindingSource:
newBindingSource.DataSource = setBindingsSource
newBindingSource.DataMember = "id"
return newBindingSource.CurrencyManager

This new BindingSource/CurrencyManager is linked with the original. When
the original changes this new one will change, usually this is used for
master-child scenarios where a field can return a child list. But since id
returns a simple integer it simply uses that as current.

So in the end you are creating an additional BindingSource/CurrencyManager
for nothing though this additional BindingSource/CurrencyManager is synced
with the original one.

Is there any
other/better way to get that "id"?


The first way you showed is good:
((DataRowView)setsBindingSource.Current)["id"]

Or a more generic way:
setBindingSource.GetItemProperties(null).Find("id" ,false).GetValue(setBindingSource.Current)

HTH,
Greetings


Feb 6 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by rk | last post: by
13 posts views Thread by rswanster | last post: by
12 posts views Thread by jyu.james | last post: by
3 posts views Thread by julien | last post: by
21 posts views Thread by sanjaymeher | last post: by
148 posts views Thread by onkar | last post: by
1 post views Thread by pillbug | last post: by
reply views Thread by lumer26 | last post: by
reply views Thread by Vinnie | last post: by
reply views Thread by lumer26 | last post: by

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.