| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
||||
|
||||
|
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 |
![]() |
| Viewing: ASP Free Forums > Programming > Code Bank > A Better Listbox Example... |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|
|