Code Bank
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingCode Bank

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
  #1  
Old February 6th, 2004, 11:41 AM
Rich's Avatar
Rich Rich is offline
Administrator
Developer Shed Admin.
 
Join Date: Sep 2003
Location: Fort Lauderdale, FL
Posts: 151 Rich User rank is Sergeant (500 - 2000 Reputation Level)Rich User rank is Sergeant (500 - 2000 Reputation Level)Rich User rank is Sergeant (500 - 2000 Reputation Level)Rich User rank is Sergeant (500 - 2000 Reputation Level)Rich User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 11 h 37 sec
Reputation Power: 10
A Better Listbox Example...

Dim LastLI As Integer
Dim INum As Integer 'Declare the 2 variables...


Private Sub Command1_Click()


If List1.Text = "" Then 'Check if nothing is selected
Else
List2.AddItem List1.Text 'Add it
End If
End Sub


Private Sub Command2_Click()
On Error Goto ErrHand 'If there is an error, go perform ErrHand
LastLI = (List2.ListIndex) 'Sets the Last index of the Listbox
List2.RemoveItem (List2.ListIndex) 'Removes it
List2.ListIndex = LastLI 'Reselects the previous selection
ErrHand: 'ErrHand, obviously


If Err.Number = 0 Then 'Error 0 is nothing, so don't do anything if there is an error 0
ElseIf Err.Number = 380 Then 'If the previous selection is unavailable then go To 1 less than that
List2.ListIndex = LastLI - 1 'Another thing: Error 380 is performed If it cannot find the list index specified (can't remember the name of it off hand
End If
End Sub


Private Sub Form_Load()
Timer1.Enabled = True
Timer1.Interval = 1
List1.Top = 0
List1.Left = 0
List2.Top = 0
List2.Left = 1200
List1.Height = 1035
List2.Height = 1035
List1.Width = 1215
List2.Width = 1215
Command1.Width = 1215
Command2.Width = 1215
Command1.Left = 0
Command1.Top = 1080
Command2.Top = 1080
Command2.Left = 1200
Command1.Height = 495
Command2.Height = 495
Command1.Caption = "Add"
Command2.Caption = "Remove"
Text1.Left = 0
Text1.Top = 1560
Text1.Height = 285
Text1.Width = 2415
Text1.Text = ""


Form1.Height = 2310


Form1.Width = 2535
'All of this sets up the Positions of th
' e controls


For i = 0 To 30
List1.AddItem "Item" & INum
INum = INum + 1
Next i
'Adds a few items
INum = 0 'Clears it, pretty pointless really...
End Sub


Private Sub List1_DblClick()


If List2.Text = "" Then
Else
List2.AddItem List1.Text 'Same as clicking On the command button
End If
End Sub


Private Sub List2_DblClick()
On Error Goto ErrHand
LastLI = (List2.ListIndex)
List2.RemoveItem (List2.ListIndex)
List2.ListIndex = LastLI 'This does the same as the command button
ErrHand:


If Err.Number = 0 Then
ElseIf Err.Number = 380 Then
List2.ListIndex = LastLI - 1
End If
End Sub


Private Sub Timer1_Timer()
Text1.Text = "List1: " & (List1.ListIndex) & " List2: " & (List2.ListIndex)
'Simply displays the ListIndexes...
End Sub

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingCode Bank > A Better Listbox Example...


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway