Drop down listbox - extra properties, possible?

P

postings

Hi

I am constantly dealing with situations whereby it would be nice to
have, say, a couple more values embedded in a listbox, that would be
nice and easy to retrieve in code.

i.e. like this:

----------------------------------------------------

Dim li = New ListItem
li.text = "Pounds Sterling"
li.value = "1"
li.value2 = "100" 'Note Value2 is not a real property
ddlTest.Items.Add(li)
li.text = "Dollars"
li.value = "2"
li.value2 = "135" 'Note Value2 is not a real property
ddlTest.Items.Add(li)
End Sub

----------------------------------------------------

So when the user select the listbox, not only can I access
ddlTest.SelectedItem and ddlTest.Selectedvalue, but I could also have
ddlTest.Selectedvalue2

I'm always having to write code around listboxes, and generally I end
up putting a few overflow values in a viewstate array, which can get
very messy having to iterate through this sort of code.

I am wondering, how would you go about adding an extra value property
to the base class of a listbox, be able to retrieve this value, and
still be able to drag a ddlistbox onto the form in VS2003.

How simple would this be to achieve?
Has anybody achieved it?
Any examples or comments?

Cheers

Alex
 
V

Visar Gashi, MCP

Hello,

You could try and extend the ListItem class and add your extra properties.

Say you create a class:

class ListItem2 : ListItem
{
...
}

Then when you use it:

ListItem2 li2 = new ListItem2();

....

ddlTest.Items.Add((ListItem)li2);

When you retrieve it:
ListItem2 li2_copy = (ListItem2)ddlTest.Items[0];

I have not tested this code, but you should get the idea from it.

Regards,
-Visar
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top