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


Reply
 
Thread Tools Display Modes
  #1  
Old 04-03-2005, 05:34 PM
sailboat sailboat is offline
Newcomer
 
Join Date: Mar 2005
Posts: 6
Default list boxes


Probably a dumb question but if you're adding items to a list box using
lstchords.additem say A, B, C and D for instance. How do you say, if A is selected then... or if B is selected in the list box then....
Reply With Quote
  #2  
Old 04-03-2005, 05:53 PM
Fat_Lip's Avatar
Fat_Lip Fat_Lip is offline
Centurion
 
Join Date: Feb 2005
Posts: 113
Default

Private Sub Command1_Click()
If List1.Text = "A" Then
MsgBox List1.Text
ElseIf List1.Text = "B" Then
MsgBox List1.Text
ElseIf List1.Text = "C" Then
MsgBox List1.Text
End If
End Sub

Private Sub Form_Load()
List1.AddItem "A"
List1.AddItem "B"
List1.AddItem "c"
End Sub

'this method is used for double clicking a listbox
Private Sub List1_DblClick()
If List1.Text = "A" Then
MsgBox List1.Text
ElseIf List1.Text = "B" Then
MsgBox List1.Text
ElseIf List1.Text = "C" Then
MsgBox List1.Text
End If
End Sub
Reply With Quote
  #3  
Old 04-03-2005, 05:59 PM
MikeJ's Avatar
MikeJ MikeJ is offline
Retread

Retired Moderator
* Expert *
 
Join Date: Sep 2002
Location: Austin, Texas
Posts: 6,742
Default

List1.List(List1.ListIndex) will return the selected item. Use it in a Select Case statement or an If statement. (Select Case is best for multiple items).
__________________
{ Lex Fori } { Locus Classicus } { Rutilus Scrinium }
Osculare pultem meam!
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
 
 
-->