Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > Variable lists in combo boxes


Reply
 
Thread Tools Display Modes
  #1  
Old 10-06-2002, 02:13 AM
CyberiaJohn
Guest
 
Posts: n/a
Default Variable lists in combo boxes


Hi all, I was wondering if anyone could help me with something, I couldn't find my specific problem using the search. I'm not a newbie at VB but I'm not an expert either, so . . .

I have a form with 2 combo boxes on it. The user will select 1 of 2 selections in the first combo box. If they select the first item in the first combo box, I want a certain list of items to show up in the second combo box. If the user selects the second item in the first combo box, then I want an entirely different list of things to appear in the second combo box.

Problem: I can seem to get *anything* to appear in the 2nd combo box! I am trying to control what happens in the 2nd combo box in the code for the 1st combo box - after all, that's where the list for the 2nd combo box will be determined.

Here is my code:

First combo box:

Private Sub Combo1_Change()
If ListIndex = 0 Then
Combo2.AddItem "Population"
Combo2.ListIndex = 0 ' the VB documentation said to add this
Else
Combo2.AddItem "Pop_state"
Combo2.AddItem "SqrKm_state"
Combo2.ListIndex = 0 ' ditto
End If
End Sub

At this point I'm not worried about code for my 2nd combo box, I just want the right selections to show up in the list!

Any help is appreciated.
Reply With Quote
  #2  
Old 10-06-2002, 02:22 AM
RemoteHoax RemoteHoax is offline
Centurion
 
Join Date: Sep 2002
Location: Chandigarh
Posts: 143
Default

Use the code in Click event of combo box
__________________
Holla! If ya hear me!
Reply With Quote
  #3  
Old 10-06-2002, 02:25 AM
ayoung ayoung is offline
Contributor
 
Join Date: Sep 2002
Location: Michigan
Posts: 623
Default

This should work

Code:
Private Sub Combo1_Click() Combo2.Clear If Combo1.ListIndex = 0 Then Combo2.AddItem "Population" 'Combo2.ListIndex = 0 End If If Combo1.ListIndex = 1 Then Combo2.Clear Combo2.AddItem "Pop_state" Combo2.AddItem "SqrKm_state" 'Combo2.ListIndex = 0 ' ditto End If End Sub
Reply With Quote
  #4  
Old 10-06-2002, 09:31 PM
CyberiaJohn
Guest
 
Posts: n/a
Default

Thanks, it worked!

LOL I feel like such an amateur. Maybe I should hang out here more often.
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
 
 
-->