473,383 Members | 1,837 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,383 software developers and data experts.

Cannot set SelectedIndex to -1 in ComboBox

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
12 5033
"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
"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
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
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
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: ross kerr | last post by:
Hi all, I have a control that extends the ComboBox object. It updates the selected item based on what the user enters in the text area. In the OnLeave event of the combobox, the selected...
3
by: Nikhil Patel | last post by:
Hi all, I am using the standard System.Windows.Forms.ComboBox controls on a form. There are 5 or 6 comboboxes and their selection depends on each other. The comboboxes behave strangely probably...
3
by: ScottO | last post by:
I would like the user to have to select something in a System.Windows.Forms.ComboBox. private void MyForm_Load(object sender, System.EventArgs e) { ... comboBox.DataSource = data;...
0
by: jac | last post by:
Hey, this.CmbDataSource = SoortKwijtingList.Items; // Arraylist this.Cmb.DisplayMember = "Omschrijving"; this.Cmb.ValueMember = "Id"; this.Cmb.SelectedIndex = -1; (short description : I...
0
by: Alex K. | last post by:
Hi all I noticed that if I link a combobox to data table (setting DataSource property), then it is very hard to clear selection by setting SelectedIndex = -1. I have to set SelectedIndex = -1...
4
by: Strahimir Antoljak | last post by:
Has anyone experienced problems with a combo box SelectIndex property? Is there a limit to the number of Items for a combo box? Namely, when I set programmatically ComboBox.SelectIndex...
0
by: Steve Dyte | last post by:
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...
5
by: Eric A. Johnson | last post by:
Hi Everyone, I am at my wit's end here. I have a combobox (combyQueryTitle) that I need to use in order to select a query for my database project. Therefore, I am using the...
18
by: Academia | last post by:
I let the use modify the text of a combobox and then I replace the selected item with the new text (in Keyup event). But if he sets the Text property to an empty string ("") that sets the...
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...
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
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.