473,406 Members | 2,549 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,406 software developers and data experts.

Tag Property for ListBox Items - This is a Comment

I have been needing a tag property for some of my list box items and I've
seen this question in this news group before where one solution was to define
a usercontrol inheiriting from the list box. I've found a Poor-Boy way of
getting a sort of tag property which probably most already know but thought
I'd share it anyway for new users:

You can define a class for your list box items and override the "ToString"
method. the listbox will show the text retruned from the "ToString" method:

Assume you have a control "MyListBox"

MyListBox.Items.Add(New MyListBoxItem("First Item", myTag1)
MyListBox.Items.Add(New MyListBoxItem("Second Item", myTag2)

.............

Friend Class MyListBoxItem
Friend v_Text as string
Friend v_Tag as object 'or whatever you want
Friend Sub New (myText, myTag)
v_Text = myText
v_Tag = myTag
End Sub
Friend ReadOnly Property Tag () as Object
Get
Return v_Tag
End Get
End Property
Friend ReadOnly Property Text as string
Get
Return v_Text
End Get
End Property
Friend Overrides Function ToSTring() as String
return Text
End Function
End Class

--
Dennis in Houston
Nov 21 '05 #1
0 1265

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

Similar topics

8
by: Vipin Kedia | last post by:
Hi I have written a code for showing the list boxes as selected using a Listitem and the selected property of the items. Now I have 2 list boxes in my page. But it shows only the selected values...
4
by: Jason | last post by:
Here is an odd issue. I am trying to shed some light on why this is causing a problem. I have an ArrayList. I am binding it to a ListBox control with has its Sort property set to True. If the...
1
by: Matthew Louden | last post by:
I created a listbox with multiple selectionmode property, but I have trouble to get a list of selected values. The following only gets the first selected value, not others. TextBox2.Text =...
0
by: Dennis | last post by:
I have been needing a tag property for some of my list box items and I've seen this question in this news group before where one solution was to define a usercontrol inheiriting from the list box. ...
3
by: andrewcw | last post by:
Who can explain this ?? : I expect 2 but I get 4 items ! private void button1_Click(object sender, EventArgs e) { object bunchOfStuff = { "foo", "fee" }; listBox1.Items.Clear();...
3
by: Ali Chambers | last post by:
Hi, I have created a listbox called "dtlist1" on my VB.NET form. I call a procedure as follows: Private Sub openfile(flname As String) dtlist1.Items.Clear() etc..
4
by: Kevin | last post by:
I'm using an ActiveX Listbox control in my Windows Forms program. I can load the listbox and have it work fine on one of my forms. But when I add the line: Me.MDIParent = frmMain the form...
2
by: michelqa | last post by:
Hi, I'm trying to display a list of string in the string collection editor just like the "items" property of an ListBox in VS IDE.... I can find many examples on the net but I cant find any...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.