Deselecting a value in a combo box

  • Thread starter Thread starter Jon Skeet [C# MVP]
  • Start date Start date
J

Jon Skeet [C# MVP]

I've got two combo boxes which are somewhat linked - the second one is
only valid if the first one has a certain value.

When I change the first one to a different value, I want to deselect
whatever's in the second box, leaving it blank. It's definitely
possible, because the databinding does is when we first enter the form
- the value is DBNull, and it manages to clear the box.

According to the docs, setting the SelectedIndex to -1 should do it -
but it doesn't. It just sets the index to 0 instead. However, bizarrely
enough, setting the SelectedIndex from the command window in the
debugger does exactly the right thing.

Any suggestions as to what might be going on?
 
Funny thing this is exactly the problem I hit last night. Databinding clears
listbox but setting selectedindex or selectedvalue does not. Next thing I'm
going to try is setting selectedindex via SendMessage. Let's keep each other
posted.
 
Thats just the ticket! Setting it twice works.

I put together a number of ComboBox "bug-fixes" into a ComboBoxEx class -
posted the code to my blog here:-
http://blog.opennetcf.org/pfoot/PermaLink.aspx?guid=dd0fe46e-dd82-428c-9982-323ef182f25c

Peter

--
Peter Foot
Windows Embedded MVP
www.inthehand.com | www.opennetcf.org

Do have an opinion on the effectiveness of Microsoft Windows Mobile and
Embedded newsgroups? Let us know!
https://www.windowsembeddedeval.com/community/newsgroups

Tim Wilson said:
I don't know if you've already seen this information, or if it even applies
in this case since it's related to the full framework, but I'll pass it
along anyways...
http://support.microsoft.com/default.aspx?scid=kb;en-us;327244
 
Cool. Nice job!

--
Tim Wilson
..Net Compact Framework MVP

Peter Foot said:
Thats just the ticket! Setting it twice works.

I put together a number of ComboBox "bug-fixes" into a ComboBoxEx class -
posted the code to my blog here:-
http://blog.opennetcf.org/pfoot/PermaLink.aspx?guid=dd0fe46e-dd82-428c-9982-323ef182f25c

Peter

--
Peter Foot
Windows Embedded MVP
www.inthehand.com | www.opennetcf.org

Do have an opinion on the effectiveness of Microsoft Windows Mobile and
Embedded newsgroups? Let us know!
https://www.windowsembeddedeval.com/community/newsgroups
 
Thanks, Tim.
Peter Foot and I have both confirmed that the KB article is applicable and
addresses exactly the issue we are seeing. The workaround works. As an
alternative, sending CB_SETCURSEL (0x14e) also works although there is a
potentially useful side effect of SelectionChanged not being fired

--
Alex Feinman
---
Visit http://www.opennetcf.org
Tim Wilson said:
I don't know if you've already seen this information, or if it even applies
in this case since it's related to the full framework, but I'll pass it
along anyways...
http://support.microsoft.com/default.aspx?scid=kb;en-us;327244
 
Back
Top