PC Review


Reply
Thread Tools Rate Thread

Cannot set SelectedIndex to -1 in ComboBox

 
 
=?Utf-8?B?U3RldmUgRHl0ZQ==?=
Guest
Posts: n/a
 
      12th Nov 2004
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
 
Reply With Quote
 
 
 
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      12th Nov 2004
"Steve Dyte" <Steve (E-Mail Removed)> 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/>

 
Reply With Quote
 
=?Utf-8?B?U3RldmUgRHl0ZQ==?=
Guest
Posts: n/a
 
      12th Nov 2004
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 (E-Mail Removed)> 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/>
>
>

 
Reply With Quote
 
=?Utf-8?B?U2NvdHQ=?=
Guest
Posts: n/a
 
      18th Nov 2004
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 (E-Mail Removed)> 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/>
>
>

 
Reply With Quote
 
=?Utf-8?B?U3RldmUgRHl0ZQ==?=
Guest
Posts: n/a
 
      18th Nov 2004
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


 
Reply With Quote
 
=?Utf-8?B?RHdlZXppbDM4?=
Guest
Posts: n/a
 
      18th Feb 2005
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
>
>

 
Reply With Quote
 
Peter Proost
Guest
Posts: n/a
 
      18th Feb 2005
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" <(E-Mail Removed)> schreef in bericht
news1BE0671-981A-40CC-8F26-(E-Mail Removed)...
> 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
> >
> >



 
Reply With Quote
 
Bernie Yaeger
Guest
Posts: n/a
 
      18th Feb 2005
See combox mdi load selectedindex (Kalvin) from 2/10/05 below.

HTH,

Bernie Yaeger

"Dweezil38" <(E-Mail Removed)> wrote in message
news1BE0671-981A-40CC-8F26-(E-Mail Removed)...
> 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
>>
>>



 
Reply With Quote
 
=?Utf-8?B?U3RldmUgRHl0ZQ==?=
Guest
Posts: n/a
 
      18th Feb 2005
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
> >
> >

 
Reply With Quote
 
=?Utf-8?B?RHdlZXppbDM4?=
Guest
Posts: n/a
 
      19th Feb 2005
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" <(E-Mail Removed)> wrote in message
> news1BE0671-981A-40CC-8F26-(E-Mail Removed)...
> > 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
> >>
> >>

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
combobox.SelectedIndex = -1 does not empty combobox =?Utf-8?B?d2VzYmlyZA==?= Microsoft Dot NET Framework Forms 1 24th Mar 2006 02:56 PM
ComboBox.SelectedIndex = -1 Ralf Ziller Microsoft Dot NET Compact Framework 2 18th Jan 2005 05:40 PM
ComboBox SelectedIndex jim Microsoft C# .NET 1 2nd Mar 2004 10:10 PM
ComboBox.SelectedIndex bug? Strahimir Antoljak Microsoft VB .NET 4 6th Jan 2004 06:09 PM
ComboBox SelectedIndex is set to 0 Albert Microsoft Dot NET Framework Forms 2 18th Sep 2003 09:02 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:05 AM.