ListBox non-Dataset load Value and discription

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there a way to load into a listbox..
one click at a time...
one row at a time...
both a value & display text without using a bound Dataset?
ValueID = 123
DisText = "Bob"
Private Sub btnSplitAdd_Click(ByVal sender As System.Object, ByVal e As _ System.EventArgs) Handles btnSplitAdd.Click

lbSplitBrkFee.BeginUpdate()
lbSplitBrkFee.Items.Add(ValueID, DisText)
lbSplitBrkFee.EndUpdate()

End Sub

User will only see "Bob", but when they click on the listbox I can get access to the ValueID 123

Thanks
Brian
 
cboT1_PayRate.BeginUpdate()
cboT1_PayRate.Items.Clear()

cboT1_PayRate.Items.Add(New ListBoxItem("AN", "Annually"))
cboT1_PayRate.Items.Add(New ListBoxItem("HR", "Hourly"))
cboT1_PayRate.Items.Add(New ListBoxItem("WK", "Weekly"))


cboT1_PayRate.EndUpdate()

....


Public Class ListBoxItem

Private listItemData As Object ' make this whatever datatype most
appropriate for you
Private listItemText As String

' This is what is displayed in the ComboBox drop-down
Public Overrides Function ToString() As String
Return listItemText
End Function

Public Sub New(ByVal itemData As Object, ByVal itemText As String)

listItemData = itemData
listItemText = itemText
End Sub

Public ReadOnly Property Data() As Object
Get
Data = listItemData
End Get

End Property

Public ReadOnly Property Text() As String
Get
Text = listItemText
End Get

End Property

End Class


HTH,
Greg

BrianDH said:
Is there a way to load into a listbox..
one click at a time...
one row at a time...
both a value & display text without using a bound Dataset?
ValueID = 123
DisText = "Bob"
Private Sub btnSplitAdd_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles btnSplitAdd.Click
 
forgot to mention; to get value back out, just cast SelectedItem back to
custom ListBoxItem class

Dim PayRateCode as String
PayRateCode=CType(cboT1_PayRate.SelectedItem, ListBoxItem).Data.ToString
 
Thank you... Workes Great!..

Still don't understand why this is not just part of the LB control.

Oh well it is MS VB.Net ;-D
 
Back
Top