| |
List Boxes are a great Selection Tool. What you need to understand with the .NET ListBox is that it stores objects. Thus, we build an Item class used to place a object in each line of the listbox. This is necessary because the ListBox does not support the ItemData property that was used in VB 6.0. We only included the routines needed for the operation of the ListBox. Notice how we can parse out the information we need from the selected class in the double_click event. We use HEADLINE Scripting with lowercase prefixes for most objects. We also use acronyms for field names (AccountNumber=ACTNBR). Please pardon the formatting from the HTML editor. Indentations were lost, and it selected some funky fonts and colors.
Copyrighted by CompuCranks.com (2006)
'****************************************************************************************
Private Sub prcBUILD_ACCOUNT_LIST()
'****************************************************************************************
Call prcSQLARM("ACCOUNTS")
lbxACCOUNT.Items.Clear()
lbxACCOUNT.BeginUpdate()
Do While rdrARM.Read()
lbxACCOUNT.Items.Add(New Item(CLng(rdrARM.Item("armACTNBR")), CStr(rdrARM.Item("armACTNME"))))
Loop
lbxACCOUNT.EndUpdate()
End Sub
'****************************************************************************************
Private Sub lbxACCOUNT_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbxACCOUNT.DoubleClick
'****************************************************************************************
hldACTNBR = CType(lbxACCOUNT.SelectedItem, Item).Number
Call prcCLEAR_ACCOUNT_DETAIL()
Call prcSET_ACCOUNT_DETAIL()
End Sub
'****************************************************************************************
Public Class Item
'****************************************************************************************
Private wrkNUMBER As Long, wrkNAME As String, wrkMODE As String
'****************************************************************************************
Public Sub New(ByVal prmNUMBER As Long, ByVal prmNAME As String, Optional ByVal prmMODE As String = " ")
'****************************************************************************************
wrkNUMBER = prmNUMBER
wrkNAME = prmNAME
wrkMODE = prmMODE
End Sub
'****************************************************************************************
Public Overrides Function toString() As String
'****************************************************************************************
If wrkMODE = "B" Then
Return wrkNUMBER & " " & wrkNAME
Else
Return wrkNAME
End If
End Function
'****************************************************************************************
Public ReadOnly Property Number() As Long
'****************************************************************************************
Get
Return wrkNUMBER
End Get
End Property
'****************************************************************************************
Public ReadOnly Property Name() As String
'****************************************************************************************
Get
Return wrkNAME
End Get
End Property
End Class
|