Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > ComboBox Behavior


Reply
 
Thread Tools Display Modes
  #1  
Old 06-04-2008, 01:00 PM
unclebill unclebill is offline
Junior Contributor
 
Join Date: Apr 2003
Location: San Diego, CA
Posts: 301
Default ComboBox Behavior


I am using a ComboBox [Style 0] to allow the user to select one of several choices. The specific choice becomes a parameter used by a procedure invoked by the ComboBox_Click event procedure.

At the end of the procedure, I want the Text property of the ComboBox restored to the default value set at Design time.

At the end of the procedure, I inserted the code:
Code:
ComboBox.Text = "Dist"
However, the ComboBox text property is set to a null string [blank] vice the desired.

I cannot understand why. My workaround has been to use the GotFocus event of the command button which is given focus at the end of the ComboBox click event procedure. This achieves the desired result but I cannot fathom why the simpler method does not work.

Any help is appreciated.
Reply With Quote
  #2  
Old 06-04-2008, 01:17 PM
Cas's Avatar
Cas Cas is offline
Senior Contributor

* Expert *
 
Join Date: May 2008
Posts: 1,012
Default

Implement the _Change event, set a breakpoint on the .Text = "Dist" line and step through from there, that might give you a clue as to what is happening.

I'm using VBA and can't reproduce the problem, but if I do the above I see that the _Change event fires twice when changing the .Text in the _Click handler, as opposed to once when changing it in a different context, which might well be related to what you're seeing in VB proper.
__________________

"Lying in bed would be an altogether perfect and supreme experience if only one had a colored pencil long enough to draw on the ceiling."

Chesterton, "Tremendous Trifles"
Reply With Quote
  #3  
Old 06-04-2008, 02:35 PM
unclebill unclebill is offline
Junior Contributor
 
Join Date: Apr 2003
Location: San Diego, CA
Posts: 301
Default

Following your suggestion, I created a ComboBox Change event procedure composed of simply a Stop statement so the program would stop on invocation of the ComboBox Change event.

When I did that, the workaround also failed.

Also, the only occurrence of the ComboBox Change Change event was when the program code set the ComboBox text property. The ComboBox Change event was NOT triggered when I selected an item from the combo box list. This apparently only triggers the ComboBox Click event.

I created a simple program to illustrate the annoyance I have ancountered.
Attached Files
File Type: zip CBTest.zip (1.8 KB, 2 views)

Last edited by unclebill; 06-04-2008 at 03:03 PM. Reason: Addition of attachment Demo Project
Reply With Quote
  #4  
Old 06-04-2008, 04:11 PM
Cas's Avatar
Cas Cas is offline
Senior Contributor

* Expert *
 
Join Date: May 2008
Posts: 1,012
Default

Quote:
Originally Posted by unclebill View Post
The ComboBox Change event was NOT triggered when I selected an item from the combo box list. This apparently only triggers the ComboBox Click event.
Yeah, that matches what it says in the MSDN:
Quote:
Occurs only if [...] the user changes the text or you change the Text property setting through code.
I had a nagging feeling that I had had some problem with the ComboBox_Click event before, and I remembered now: It's not possible to unload control array members in the handler, see here. I don't see any connection between the two oddities, other than their being odd, but figured it can't hurt to mention it.

I'm afraid I don't have anything more constructive to offer atm.
__________________

"Lying in bed would be an altogether perfect and supreme experience if only one had a colored pencil long enough to draw on the ceiling."

Chesterton, "Tremendous Trifles"
Reply With Quote
  #5  
Old 06-04-2008, 06:06 PM
Cerian Knight's Avatar
Cerian Knight Cerian Knight is offline
Multi-Technologist

Super Moderator
* Expert *
 
Join Date: May 2004
Location: Michigan
Posts: 3,740
Default

I have no problem getting it to work on Win2K after commenting out: 'cmdClose.SetFocus
Just a guess that you are not running VB6 SP6.
__________________
"May the code that you write never work in ways that you didn't expect; and may the code that you didn't write never require you to maintain it". - Ancient Chinese Proverb
Reply With Quote
  #6  
Old 06-04-2008, 07:26 PM
unclebill unclebill is offline
Junior Contributor
 
Join Date: Apr 2003
Location: San Diego, CA
Posts: 301
Default

The only indication I see in the Help About response is Version 8176 VBA 6.0.8169 forms3: 11.0.5709. Does that tell you enough to kow what service pack I might have (if any)?

Thanks.

I got smart (well, sort of) and downloaded and installed SP6. It solved the problem.

Thanks.

Last edited by unclebill; 06-04-2008 at 07:44 PM. Reason: Update status
Reply With Quote
  #7  
Old 06-04-2008, 10:02 PM
unclebill unclebill is offline
Junior Contributor
 
Join Date: Apr 2003
Location: San Diego, CA
Posts: 301
Default

Wow! With SP6, my executable is much smaller. Before installing SP6 for VB6, I had a project that compiles to about 920K. After SP6, it compiles in about 1/3 the time and the .exe file is about 500K!

Is this typical in your experience? Thanks.
Reply With Quote
  #8  
Old 06-05-2008, 11:57 AM
Cerian Knight's Avatar
Cerian Knight Cerian Knight is offline
Multi-Technologist

Super Moderator
* Expert *
 
Join Date: May 2004
Location: Michigan
Posts: 3,740
Default

I can't recall comparing a base install against any service packs...but it is good to know that it is working well for you. There are lots of behavioral quirks cleaned up by SP6, as it contains all previous SP updates.
__________________
"May the code that you write never work in ways that you didn't expect; and may the code that you didn't write never require you to maintain it". - Ancient Chinese Proverb
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->