By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,759 Members | 1,255 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,759 IT Pros & Developers. It's quick & easy.

Bind DataView to 2 ComboBoxes

P: n/a
hi

i bounded the same dataview to 2 different comboboxes. now, when i change
the selectedIndex of combobox1, it automatically changes the selectedIndex
of combobox2.
does this mean, that the combobox selects the item on the base of some kind
of a pointer on the dataview? if yes, is there a class inside the framework,
which i can use to change this pointer on the dataview myself?

thanx for any hint.
jazper
Nov 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Hi,

"Jazper Manto" <ej*****@hotmail.com> wrote in message
news:uW**************@TK2MSFTNGP09.phx.gbl...
hi

i bounded the same dataview to 2 different comboboxes. now, when i change
the selectedIndex of combobox1, it automatically changes the selectedIndex
of combobox2.
does this mean, that the combobox selects the item on the base of some
kind
of a pointer on the dataview?
Well, there is a little more to it. The DataView itself doesn't mantain the
position, but a CurrencyManager does. A CurrencyManager is unique for each
(bound) DataSource/DataMember within a BindingContext. By default a
BindingContext is shared between a Form and all of its controls.

If you want independent navigating with the same DataSource/DataMember, you
need to assign a new BindingContext to the different controls as this would
result in a different CurrencyManager (for the same DataSource/DataMember).
if yes, is there a class inside the framework,
which i can use to change this pointer on the dataview myself?
The general way the get a CurrencyManager would be:
CurrencyManager cm = (CurrencyManager)BindingContext[dataSource,
dataMember];

But if the DataMember wasn't used for binding then it can be omitted, eg. :
CurrencyManager cm = (CurrencyManager)BindingContext[myDataView];

Lookup the CurrencyManager class, it has a few properties, like Position
which you can read and change.
HTH,
Greetings


thanx for any hint.
jazper

Nov 17 '05 #2

P: n/a
> Well, there is a little more to it. The DataView itself doesn't mantain
the
position, but a CurrencyManager does. A CurrencyManager is unique for each (bound) DataSource/DataMember within a BindingContext. By default a
BindingContext is shared between a Form and all of its controls.


perfect answer. thank you.
you said the BindingContext is shared between a Form and all of its
controls... hmmm. i have another problem which has been explained while i
read your statement. i have a winform with a panel-object in it. this panel
contains bounded comboboxes. as soon as i grap this panel and add it to
another controlcollection of another form it gets another CurrencyManager.

can i avoid this problem or set back the CurrencyManager in some way?

thanx jazper
Nov 17 '05 #3

P: n/a
Hi,
[Inline]

"Jazper Manto" <ej*****@hotmail.com> wrote in message
news:uG**************@TK2MSFTNGP14.phx.gbl...
Well, there is a little more to it. The DataView itself doesn't mantain the
position, but a CurrencyManager does. A CurrencyManager is unique for

each
(bound) DataSource/DataMember within a BindingContext. By default a
BindingContext is shared between a Form and all of its controls.


perfect answer. thank you.
you said the BindingContext is shared between a Form and all of its
controls...


Yes, to explain this a little more, the Form creates a BindingContext, then
when you bind to any Control it needs a BindingContext but if none have been
set to that Control it will use the BindingContext of the parent.

On the other hand, if a BindingContext has been explicitly set to a Control
it will no longer use its parents one, not even when you move the Control
between forms.
hmmm. i have another problem which has been explained while i
read your statement. i have a winform with a panel-object in it. this
panel
contains bounded comboboxes. as soon as i grap this panel and add it to
another controlcollection of another form it gets another CurrencyManager.

can i avoid this problem or set back the CurrencyManager in some way?
Yes, by keeping the same BindingContext.

In Form load (preferably before binding, but it's not mandatory) explicitly
set the panel's BindingContext. Like explained above, once you have set it
explicitly it won't change when you add the panel to another Form.

You still have a choice between just using the parent's BindingContext or
creating a new one, eg:

panel1.BindingContext = new BindingContext();
---or---
panel1.BindingContext = this.BindingContext();

The latter may look useless but it isn't because here you're setting it
explicitly which makes the difference.

HTH,
Greetings

thanx jazper

Nov 17 '05 #4

P: n/a
hi bart

again thank you for your explanations.
Yes, to explain this a little more, the Form creates a BindingContext, then when you bind to any Control it needs a BindingContext but if none have been set to that Control it will use the BindingContext of the parent.

On the other hand, if a BindingContext has been explicitly set to a Control it will no longer use its parents one, not even when you move the Control
between forms.


perfect. excactly the solution i needed. :-)
cheers, jazper
Nov 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.