473,785 Members | 2,425 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1289

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

Similar topics

8
2844
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 of the last list box in both the list boxes. If i reverse the calls to the filllistbox methods it shows the value selected for the 1st list box in both the listboxes. I have the code for my method below. Is there a way I can solve this problem?
4
5910
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 ArrayList only has one element in it everything works ok. But as soon as I have more than one element, I get the following exception when the control loads up: "Cannot modify the Items collection when the DataSource property is set.". Anybody...
1
8218
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 = ListBox1.SelectedValue Please help!! Thanks
0
353
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. 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...
3
3530
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(); System.Windows.Forms.ListBox.ObjectCollection lboxObjCol = new ListBox.ObjectCollection(listBox1, bunchOfStuff); listBox1.Items.AddRange(lboxObjCol);
3
2298
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
1844
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 appears with the items invisible. The scrollbar shows that the items are in the listbox--I just can't see any of them. If I comment out the above line, the items appear normally.
2
7828
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 example like items property of a listbox... I mean the String collection editor with the text "Enter the strings in the collection (on per line)" Is anybody can point me to the right object to use to define my string
0
9646
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9483
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10096
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8982
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6742
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5386
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4055
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3658
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2887
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.