Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

O.K.

 

To add items to a combo box, I know I use

cbo.items.add("myItem")

 

however that adds the items to the name and value fields. I want to add something different to the Value field than what is in the name field. Can I do this at runtime?

Ignorance begins with I.
Posted

I don't know if I have to ask this or not. But are you developing a windows application or a web application? :D It is confusing that you're using the "combo box" term but you also mentioned the Name and Value field. :D

 

If you're developing a windows application. If this is true then it is out of my reach. I don't even think it's possible to do what you want.

 

But if you're developing a web application then you should create a new item object (the class would be ListItem if I'm not mistaken). Within that new object you can specify different values for the Name and Value field. With that new object you're now able to add it.

 

Hope it helps.

Amir Syafrudin
  • 2 weeks later...
Posted

Sorry,

Long time App developer now doing alot of ASP.Net. yes it is for a web, sorry a dropdownlist. I know if I add the control dynamically I can add the value field but this is a dropdownlist already on the form. Can I still somehow reference the value field? Thanks for the help.

Ignorance begins with I.
Posted (edited)

here's what Amir was talking about. when you add an item, it will allow you to add objects. so create a basic object for your "items", then add it.

 

dim o as New InfoObject

o.setName = "myname"

o.setValue = "myvalue"

cbo.items.add(o)

 

For your InfoObect, you will want get/set functions (or use properties if you can so you can just say o.name="myname"

 

You will also need to override the toString function and return what you want it to display. For example:

Public Overrides Function toString() as String

return me.name

End Function

in this case, your combobox will display the name of your object in the list

 

Finally, what this results in is if you ask the combobox for its "SelectedItem" it will return an object of the type you added, so in this case InfoObject. so you can say

o = cbo.selectedItem

name = o.getName

value = o.getValue

Edited by alreadyused

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...