I am experiencing strange behavior working with multiple
ComboBoxes on a form.

I have several ComboBoxes that I configure in code the
way I have in the past (only a single ComboxBox on the
form). Whatever I configure the last ComboxBox to, it
changes all the previous ComboBoxes to the same displayed
value.

Here is the code:

private void Form1_Load(object sender, System.EventArgs e)
{
da.Fill(ds.tblQuestions);
daTypes.Fill(ds.tblQuestionTypes);

BindCB1();
BindCB2();
}

private void BindCB1()
{
comboBox1.DataSource = ds;
comboBox1.DisplayMember
= "tblQuestionTypes.QuestionTypeDesc";
comboBox1.ValueMember
= "tblQuestionTypes.QuestionTypeNumber";
comboBox1.DataBindings.Add("SelectedValue",
ds, "tblQuestions.Question01Type");
comboBox1.DropDownStyle.Equals("DropDownList");
}

private void BindCB2()
{
comboBox2.DataSource = ds;
comboBox2.DisplayMember
= "tblQuestionTypes.QuestionTypeDesc";
comboBox2.ValueMember
= "tblQuestionTypes.QuestionTypeNumber";
comboBox2.DataBindings.Add("SelectedValue",
ds, "tblQuestions.Question02Type");
comboBox2.DropDownStyle.Equals("DropDownList");
}

Any help is greatly appreciated.

Strange ComboBox Behavior by ken

ken
Thu Oct 23 14:23:02 CDT 2003

Try using two copies of ds, ie ds1 and ds2. But do not
say ds2 = ds1; say ds2 = new (ds1);
See if this helps :)

>-----Original Message-----
>I am experiencing strange behavior working with multiple
>ComboBoxes on a form.
>
>I have several ComboBoxes that I configure in code the
>way I have in the past (only a single ComboxBox on the
>form). Whatever I configure the last ComboxBox to, it
>changes all the previous ComboBoxes to the same
displayed
>value.
>
>Here is the code:
>
>private void Form1_Load(object sender, System.EventArgs
e)
>{
> da.Fill(ds.tblQuestions);
> daTypes.Fill(ds.tblQuestionTypes);
>
> BindCB1();
> BindCB2();
>}
>
>private void BindCB1()
>{
> comboBox1.DataSource = ds;
> comboBox1.DisplayMember
>= "tblQuestionTypes.QuestionTypeDesc";
> comboBox1.ValueMember
>= "tblQuestionTypes.QuestionTypeNumber";
> comboBox1.DataBindings.Add("SelectedValue",
>ds, "tblQuestions.Question01Type");
> comboBox1.DropDownStyle.Equals("DropDownList");
>}
>
>private void BindCB2()
>{
> comboBox2.DataSource = ds;
> comboBox2.DisplayMember
>= "tblQuestionTypes.QuestionTypeDesc";
> comboBox2.ValueMember
>= "tblQuestionTypes.QuestionTypeNumber";
> comboBox2.DataBindings.Add("SelectedValue",
>ds, "tblQuestions.Question02Type");
> comboBox2.DropDownStyle.Equals("DropDownList");
>}
>
>Any help is greatly appreciated.
>
>
>.
>

Re: Strange ComboBox Behavior by David

David
Thu Oct 23 14:44:48 CDT 2003

In article <01f701c3998b$82781ec0$a301280a@phx.gbl>, Greg Smith wrote:
> I am experiencing strange behavior working with multiple
> ComboBoxes on a form.
>
> I have several ComboBoxes that I configure in code the
> way I have in the past (only a single ComboxBox on the
> form). Whatever I configure the last ComboxBox to, it
> changes all the previous ComboBoxes to the same displayed
> value.

If I understand your problem correctly, what's happening is that all the
combo boxes on the page are binding to the same BindingContext. So when
you change the current row in your default BindingContext, all the combo
boxes are adjusting themselves to reflect the current row. The simple
fix is to create a new Binding Context for one of the boxes, like...

private void BindCB2()
{
comboBox2.BindingContext = new BindingContext();
comboBox2.DataSource = ds;
comboBox2.DisplayMember = "tblQuestionTypes.QuestionTypeDesc";
comboBox2.ValueMember = "tblQuestionTypes.QuestionTypeNumber";
comboBox2.DataBindings.Add("SelectedValue", ds,
"tblQuestions.Question02Type");
comboBox2.DropDownStyle.Equals("DropDownList");
}

BTW, I'm pretty sure the line:

comboBox2.DropDownStyle.Equals("DropDownList");

doesn't do anything useful. All "Equals" does is compare items and
return a boolean. Since you aren't doing anything with the return
value, this is essentially a no-op (or possibly I'm reading this wrong,
the original indenting was a little funny here).

--
David
dfoster at
hotpop dot com

Re: Strange ComboBox Behavior by v-yiy

v-yiy
Thu Oct 23 20:29:02 CDT 2003

Hi Greg,
Do you mean , after you bind the ComboBox2, then any selection changes on
ComboBox2 will also change the other ComboBox to the according value?
If yes, does our community member's solutions solve your problem?
If you still have problem on this issue, please be free to post it on the
group!
I'll follow-up with you.
Thanks!

Best regards,

Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
You should not reply this mail directly, "Online" should be removed before
sending, Thanks!

--------------------
| From: David <dfoster@127.0.0.1>
| Subject: Re: Strange ComboBox Behavior
| References: <01f701c3998b$82781ec0$a301280a@phx.gbl>
| Message-ID: <slrnbpgbti.8g7.dfoster@woofix.local.dom>
| User-Agent: slrn/0.9.7.4 (Linux)
| Newsgroups: microsoft.public.dotnet.framework.windowsforms
| Date: Thu, 23 Oct 2003 12:44:48 -0700
| NNTP-Posting-Host: 129-138.175-24.bham.rr.com 24.175.138.129
| Lines: 1
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.windowsforms:55123
| X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms
|
| In article <01f701c3998b$82781ec0$a301280a@phx.gbl>, Greg Smith wrote:
| > I am experiencing strange behavior working with multiple
| > ComboBoxes on a form.
| >
| > I have several ComboBoxes that I configure in code the
| > way I have in the past (only a single ComboxBox on the
| > form). Whatever I configure the last ComboxBox to, it
| > changes all the previous ComboBoxes to the same displayed
| > value.
|
| If I understand your problem correctly, what's happening is that all the
| combo boxes on the page are binding to the same BindingContext. So when
| you change the current row in your default BindingContext, all the combo
| boxes are adjusting themselves to reflect the current row. The simple
| fix is to create a new Binding Context for one of the boxes, like...
|
| private void BindCB2()
| {
| comboBox2.BindingContext = new BindingContext();
| comboBox2.DataSource = ds;
| comboBox2.DisplayMember = "tblQuestionTypes.QuestionTypeDesc";
| comboBox2.ValueMember = "tblQuestionTypes.QuestionTypeNumber";
| comboBox2.DataBindings.Add("SelectedValue", ds,
| "tblQuestions.Question02Type");
| comboBox2.DropDownStyle.Equals("DropDownList");
| }
|
| BTW, I'm pretty sure the line:
|
| comboBox2.DropDownStyle.Equals("DropDownList");
|
| doesn't do anything useful. All "Equals" does is compare items and
| return a boolean. Since you aren't doing anything with the return
| value, this is essentially a no-op (or possibly I'm reading this wrong,
| the original indenting was a little funny here).
|
| --
| David
| dfoster at
| hotpop dot com
|


Re: Strange ComboBox Behavior by Greg

Greg
Fri Oct 24 10:05:41 CDT 2003

Thank a million David. That was the fix. :->

"David" <dfoster@127.0.0.1> wrote in message
news:slrnbpgbti.8g7.dfoster@woofix.local.dom...
> In article <01f701c3998b$82781ec0$a301280a@phx.gbl>, Greg Smith wrote:
> > I am experiencing strange behavior working with multiple
> > ComboBoxes on a form.
> >
> > I have several ComboBoxes that I configure in code the
> > way I have in the past (only a single ComboxBox on the
> > form). Whatever I configure the last ComboxBox to, it
> > changes all the previous ComboBoxes to the same displayed
> > value.
>
> If I understand your problem correctly, what's happening is that all the
> combo boxes on the page are binding to the same BindingContext. So when
> you change the current row in your default BindingContext, all the combo
> boxes are adjusting themselves to reflect the current row. The simple
> fix is to create a new Binding Context for one of the boxes, like...
>
> private void BindCB2()
> {
> comboBox2.BindingContext = new BindingContext();
> comboBox2.DataSource = ds;
> comboBox2.DisplayMember = "tblQuestionTypes.QuestionTypeDesc";
> comboBox2.ValueMember = "tblQuestionTypes.QuestionTypeNumber";
> comboBox2.DataBindings.Add("SelectedValue", ds,
> "tblQuestions.Question02Type");
> comboBox2.DropDownStyle.Equals("DropDownList");
> }
>
> BTW, I'm pretty sure the line:
>
> comboBox2.DropDownStyle.Equals("DropDownList");
>
> doesn't do anything useful. All "Equals" does is compare items and
> return a boolean. Since you aren't doing anything with the return
> value, this is essentially a no-op (or possibly I'm reading this wrong,
> the original indenting was a little funny here).
>
> --
> David
> dfoster at
> hotpop dot com