473,396 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

ListBox non-Dataset load Value and discription

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

Nov 20 '05 #1
3 1188
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" <Br*****@discussions.microsoft.com> wrote in message
news:48**********************************@microsof t.com...
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

Nov 20 '05 #2
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

"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
news:O$**************@TK2MSFTNGP09.phx.gbl...
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" <Br*****@discussions.microsoft.com> wrote in message
news:48**********************************@microsof t.com...
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


Nov 20 '05 #3
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

"Greg Burns" wrote:
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

"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
news:O$**************@TK2MSFTNGP09.phx.gbl...
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" <Br*****@discussions.microsoft.com> wrote in message
news:48**********************************@microsof t.com...
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



Nov 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Oddball | last post by:
Ok - I have a ListBox control and I'm ready to write my own DrawItem event handler. What I want to draw as the item is another control. I have created a user control that I would like to list in...
12
by: Shawn | last post by:
I know that I can use DisplayMember and ValueMember when using a DataSource on the ListBox, but is it possible to use the same technique when using ListBox.Items.Add method? In my application I...
3
by: Richard Albrecht | last post by:
I have been trying to figure out for days on how to read values from a Bound ListBox. The listBox gets the values from an Access Table. I can read values fine for Non-Bound ListBoxes, But the...
1
by: A. Spiehler | last post by:
I'm trying to fill a listBox control with string members from an array of objects. I think using data binding is supposed to be the easiest way to do this. I've never used data binding before and...
3
by: ML | last post by:
I have used Allen Brown's technique for filling a listbox on a form with the names of files in a certain disc folder. It works well. I am now giving the user the option to print the form...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.