nate Posted June 10, 2007 Posted June 10, 2007 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? Quote Ignorance begins with I.
amir100 Posted June 13, 2007 Posted June 13, 2007 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. Quote Amir Syafrudin
nate Posted June 23, 2007 Author Posted June 23, 2007 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. Quote Ignorance begins with I.
alreadyused Posted June 28, 2007 Posted June 28, 2007 (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 June 28, 2007 by alreadyused Quote
amir100 Posted July 2, 2007 Posted July 2, 2007 Can I still somehow reference the value field? Yes, you can. Take a look at alreadyused's explanation. :D Hope it helps. Quote Amir Syafrudin
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.