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

Cannot set SelectedIndex to -1 in ComboBox

P: n/a
Hi,

I've narrowed down a problem I've been having filling a combobox with the
results of a query stored in a datatable. I'm setting the ValueMember and
DisplayMember to the relevant column names, and then I want to make sure
nothing is selected.

By default it appears that if you do nothing, the first item (0) is
selected. However, I want to set the SelectedIndex to -1.

If I have a standalone window it works, but if I have a window that has an
mdiparent set, it ignores my attempts to set the SelectedIndex to -1 and
always selects item 0.

(here's my code...)
ComboBox1.DataSource = dt
ComboBox1.ValueMember = "chCountryCode"
ComboBox1.DisplayMember = "chCountryDesc"
ComboBox1.SelectedIndex = -1

I've already tried setting SelectedIndex = -1 twice, but that doesn't fix
it. The only thing that seems to fix it is making the window non-childmdi,
but our application is an MDI style app!

Is this a bug? Any ideas please?

Many thanks,

Steve
Nov 21 '05 #1
Share this Question
Share on Google+
12 Replies


P: n/a
"Steve Dyte" <Steve Dy**@discussions.microsoft.com> schrieb:
ComboBox1.ValueMember = "chCountryCode"
ComboBox1.DisplayMember = "chCountryDesc"
ComboBox1.SelectedIndex = -1

I've already tried setting SelectedIndex = -1 twice, but that doesn't fix
it. The only thing that seems to fix it is making the window non-childmdi,
but our application is an MDI style app!


BUG: ComboBox Does Not Clear When You Set SelectedIndex to -1
<URL:http://support.microsoft.com/?scid=kb;EN-US;327244>

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 21 '05 #2

P: n/a
"Steve Dyte" <Steve Dy**@discussions.microsoft.com> schrieb:
ComboBox1.ValueMember = "chCountryCode"
ComboBox1.DisplayMember = "chCountryDesc"
ComboBox1.SelectedIndex = -1

I've already tried setting SelectedIndex = -1 twice, but that doesn't fix
it. The only thing that seems to fix it is making the window non-childmdi,
but our application is an MDI style app!


BUG: ComboBox Does Not Clear When You Set SelectedIndex to -1
<URL:http://support.microsoft.com/?scid=kb;EN-US;327244>

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 21 '05 #3

P: n/a
Hi, I'm afraid this doesn't fix the problem. I'd already seen this "bug" and
tried the workarounds. It says it affects version 1.0 of the Framework,
whereas we're on v1.1.

If I create a plain window, it works fine. It's only when my window is a
child window of an MDIParent that it ignores my attemps to set SelectedIndex
= -1.

You should be able to recreate this fairly easily...

Create a form with two MenuItems on it...

Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MenuItem1.Click

' if I do this it will ignore my SelectedIndex = -1 and set it to 0
Dim x As New Form2
x.MdiParent = Me
x.Show()
End Sub

Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MenuItem2.Click

' if I do this, it will set SelectedIndex = -1 with no problems!!
Dim x As New Form2
x.Show()

End Sub

FYI, Form2 is my test form. It has one combobox, and code in the form load
to get a DataTable, bind it to the combobox and try to set the SelectedIndex
= -1 (see my original post)

Thanks,

Steve
"Herfried K. Wagner [MVP]" wrote:
"Steve Dyte" <Steve Dy**@discussions.microsoft.com> schrieb:
ComboBox1.ValueMember = "chCountryCode"
ComboBox1.DisplayMember = "chCountryDesc"
ComboBox1.SelectedIndex = -1

I've already tried setting SelectedIndex = -1 twice, but that doesn't fix
it. The only thing that seems to fix it is making the window non-childmdi,
but our application is an MDI style app!


BUG: ComboBox Does Not Clear When You Set SelectedIndex to -1
<URL:http://support.microsoft.com/?scid=kb;EN-US;327244>

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 21 '05 #4

P: n/a
Hi, I'm afraid this doesn't fix the problem. I'd already seen this "bug" and
tried the workarounds. It says it affects version 1.0 of the Framework,
whereas we're on v1.1.

If I create a plain window, it works fine. It's only when my window is a
child window of an MDIParent that it ignores my attemps to set SelectedIndex
= -1.

You should be able to recreate this fairly easily...

Create a form with two MenuItems on it...

Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MenuItem1.Click

' if I do this it will ignore my SelectedIndex = -1 and set it to 0
Dim x As New Form2
x.MdiParent = Me
x.Show()
End Sub

Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MenuItem2.Click

' if I do this, it will set SelectedIndex = -1 with no problems!!
Dim x As New Form2
x.Show()

End Sub

FYI, Form2 is my test form. It has one combobox, and code in the form load
to get a DataTable, bind it to the combobox and try to set the SelectedIndex
= -1 (see my original post)

Thanks,

Steve
"Herfried K. Wagner [MVP]" wrote:
"Steve Dyte" <Steve Dy**@discussions.microsoft.com> schrieb:
ComboBox1.ValueMember = "chCountryCode"
ComboBox1.DisplayMember = "chCountryDesc"
ComboBox1.SelectedIndex = -1

I've already tried setting SelectedIndex = -1 twice, but that doesn't fix
it. The only thing that seems to fix it is making the window non-childmdi,
but our application is an MDI style app!


BUG: ComboBox Does Not Clear When You Set SelectedIndex to -1
<URL:http://support.microsoft.com/?scid=kb;EN-US;327244>

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 21 '05 #5

P: n/a
Does .NET Framework 1.1 SP1 fix the SelectedIndex = -1 problem?

The list of fixes in .NET Framework 1.1 SP1 at
http://support.microsoft.com/kb/867460 includes the following:

FIX: The value of the SelectedIndex property of the ComboBox control does
not change when you set the text by using the Text property (839616)
http://support.microsoft.com/kb/839616

This in turn has a reference to:
BUG: ComboBox Does Not Clear When You Set SelectedIndex to -1 (327244)
http://support.microsoft.com/kb/327244.

I have had much trouble not knowing whether I have bound incorrectly, have
an error in my own combobox class that displays two columns in the pull-down,
or whether I'm a victim of the many bugs in the ComboBox that seem to stem
back to the SelectedIndex = -1 problem. More likely, I have some combination
of all of these, which makes debugging a nightmare. :-(

Has anyone tried it out SP1 to find out? I'm going to try tonight.
Scott.


"Herfried K. Wagner [MVP]" wrote:
"Steve Dyte" <Steve Dy**@discussions.microsoft.com> schrieb:
ComboBox1.ValueMember = "chCountryCode"
ComboBox1.DisplayMember = "chCountryDesc"
ComboBox1.SelectedIndex = -1

I've already tried setting SelectedIndex = -1 twice, but that doesn't fix
it. The only thing that seems to fix it is making the window non-childmdi,
but our application is an MDI style app!


BUG: ComboBox Does Not Clear When You Set SelectedIndex to -1
<URL:http://support.microsoft.com/?scid=kb;EN-US;327244>

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 21 '05 #6

P: n/a
Hi, we already have Framework 1.1 with SP1 applied.

The problem we have is easily reproducable... It ONLY happens if you have

1) An MDI Parent window
2) Open a MDI Child window from the MDI Parent window (i.e. setting the
MDIParent property of the child window)
3) Have code in the form_load event that fills a combobox by binding it to a
dataset and set the SelectedIndex = -1

If you change Step 2) to load a new instance of the window without setting
the MDIParent property, the problem does not happen and you can quite happily
set SelectedIndex = -1

Thanks,

Steve
Nov 21 '05 #7

P: n/a
Steve,

I have the same problem. Did you ever find a solution? Mdi CHild form with
Combo Box and I need it empty (Blank) when form loads.

Thanks AL

"Steve Dyte" wrote:
Hi, we already have Framework 1.1 with SP1 applied.

The problem we have is easily reproducable... It ONLY happens if you have

1) An MDI Parent window
2) Open a MDI Child window from the MDI Parent window (i.e. setting the
MDIParent property of the child window)
3) Have code in the form_load event that fills a combobox by binding it to a
dataset and set the SelectedIndex = -1

If you change Step 2) to load a new instance of the window without setting
the MDIParent property, the problem does not happen and you can quite happily
set SelectedIndex = -1

Thanks,

Steve

Nov 21 '05 #8

P: n/a
If I remember it correctly it is a bug in vs2002, because here in my vs2003
it doesn't happen and you should call SelectedIndex = -1 twice

hth Greetz Peter

"Dweezil38" <B_*************@msn.com> schreef in bericht
news:D1**********************************@microsof t.com...
Steve,

I have the same problem. Did you ever find a solution? Mdi CHild form with
Combo Box and I need it empty (Blank) when form loads.

Thanks AL

"Steve Dyte" wrote:
Hi, we already have Framework 1.1 with SP1 applied.

The problem we have is easily reproducable... It ONLY happens if you have
1) An MDI Parent window
2) Open a MDI Child window from the MDI Parent window (i.e. setting the
MDIParent property of the child window)
3) Have code in the form_load event that fills a combobox by binding it to a dataset and set the SelectedIndex = -1

If you change Step 2) to load a new instance of the window without setting the MDIParent property, the problem does not happen and you can quite happily set SelectedIndex = -1

Thanks,

Steve

Nov 21 '05 #9

P: n/a
See combox mdi load selectedindex (Kalvin) from 2/10/05 below.

HTH,

Bernie Yaeger

"Dweezil38" <B_*************@msn.com> wrote in message
news:D1**********************************@microsof t.com...
Steve,

I have the same problem. Did you ever find a solution? Mdi CHild form with
Combo Box and I need it empty (Blank) when form loads.

Thanks AL

"Steve Dyte" wrote:
Hi, we already have Framework 1.1 with SP1 applied.

The problem we have is easily reproducable... It ONLY happens if you have

1) An MDI Parent window
2) Open a MDI Child window from the MDI Parent window (i.e. setting the
MDIParent property of the child window)
3) Have code in the form_load event that fills a combobox by binding it
to a
dataset and set the SelectedIndex = -1

If you change Step 2) to load a new instance of the window without
setting
the MDIParent property, the problem does not happen and you can quite
happily
set SelectedIndex = -1

Thanks,

Steve

Nov 21 '05 #10

P: n/a
Hi, kind of...

We gave up with the VB combo because of this problem. We ended up using the
Infragistcs UltraComboEditor control instead, and this works just fine - (we
were already using the Infragistics UltraGrid control).

We did log this problem as a "bug" with our Microsoft Support/Sales contact
but never heard back...

Steve

"Dweezil38" wrote:
Steve,

I have the same problem. Did you ever find a solution? Mdi CHild form with
Combo Box and I need it empty (Blank) when form loads.

Thanks AL

"Steve Dyte" wrote:
Hi, we already have Framework 1.1 with SP1 applied.

The problem we have is easily reproducable... It ONLY happens if you have

1) An MDI Parent window
2) Open a MDI Child window from the MDI Parent window (i.e. setting the
MDIParent property of the child window)
3) Have code in the form_load event that fills a combobox by binding it to a
dataset and set the SelectedIndex = -1

If you change Step 2) to load a new instance of the window without setting
the MDIParent property, the problem does not happen and you can quite happily
set SelectedIndex = -1

Thanks,

Steve

Nov 21 '05 #11

P: n/a
Bernie

I have a couple of problems with Kalvin's solution. First off what is a
CategoryCollection, CategoryServer and Category. I can't find these
referrences in help. Also, loading thousands of items, individually into each
combobox is not feasable. It will slow down the application. There has to be
another solution, hopefully without having to "BUY" another ActiveX component.

Thanks

"Bernie Yaeger" wrote:
See combox mdi load selectedindex (Kalvin) from 2/10/05 below.

HTH,

Bernie Yaeger

"Dweezil38" <B_*************@msn.com> wrote in message
news:D1**********************************@microsof t.com...
Steve,

I have the same problem. Did you ever find a solution? Mdi CHild form with
Combo Box and I need it empty (Blank) when form loads.

Thanks AL

"Steve Dyte" wrote:
Hi, we already have Framework 1.1 with SP1 applied.

The problem we have is easily reproducable... It ONLY happens if you have

1) An MDI Parent window
2) Open a MDI Child window from the MDI Parent window (i.e. setting the
MDIParent property of the child window)
3) Have code in the form_load event that fills a combobox by binding it
to a
dataset and set the SelectedIndex = -1

If you change Step 2) to load a new instance of the window without
setting
the MDIParent property, the problem does not happen and you can quite
happily
set SelectedIndex = -1

Thanks,

Steve


Nov 21 '05 #12

P: n/a
Steve,

I found the solution!!! The way to get the Child MDI forms to clear their
combo boxes is the set the SelectedIndex to -1 in the Parent form after
calling the show method for opening the MDI child. I tested it and it seems
to work fine.

Dweezil

"Steve Dyte" wrote:
Hi, kind of...

We gave up with the VB combo because of this problem. We ended up using the
Infragistcs UltraComboEditor control instead, and this works just fine - (we
were already using the Infragistics UltraGrid control).

We did log this problem as a "bug" with our Microsoft Support/Sales contact
but never heard back...

Steve

"Dweezil38" wrote:
Steve,

I have the same problem. Did you ever find a solution? Mdi CHild form with
Combo Box and I need it empty (Blank) when form loads.

Thanks AL

"Steve Dyte" wrote:
Hi, we already have Framework 1.1 with SP1 applied.

The problem we have is easily reproducable... It ONLY happens if you have

1) An MDI Parent window
2) Open a MDI Child window from the MDI Parent window (i.e. setting the
MDIParent property of the child window)
3) Have code in the form_load event that fills a combobox by binding it to a
dataset and set the SelectedIndex = -1

If you change Step 2) to load a new instance of the window without setting
the MDIParent property, the problem does not happen and you can quite happily
set SelectedIndex = -1

Thanks,

Steve

Nov 21 '05 #13

This discussion thread is closed

Replies have been disabled for this discussion.