473,406 Members | 2,620 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.

Very quick question on comboxbox items..

Hi,

As far as i can tell this can't be done, but thought i'd quickly ask, I have
4 labels in my combobox, and i want to add them to the box with a numeric
"value" and then get that value of the currently selected item. I want the
combobox to display the text not the value of course..

Is this possible with the standard combobox??

Thanks,
Dan
Nov 20 '05 #1
12 1194
Hi Dan,

Same question at 10:25am today - I guess it's one of those. ;-)

Assign an object to the combobox rather than a single value. Your override
of the object's ToString will provide the text for display, but accessing the
Item in code will get the whole object.

Regards,
Fergus
Nov 20 '05 #2
* "Dan Keeley" <ma********@hotmail.com> scripsit:
As far as i can tell this can't be done, but thought i'd quickly ask, I have
4 labels in my combobox, and i want to add them to the box with a numeric
"value" and then get that value of the currently selected item. I want the
combobox to display the text not the value of course..


Have a look at this discussion:

<http://www.google.de/groups?selm=bme0qq%24loej5%241%40ID-208219.news.uni-berlin.de>

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #3
>
Have a look at this discussion:

<http://www.google.de/groups?selm=bme...19.news.uni-be
rlin.de>
--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>


Excellent thanks for both of those very quick replies!!

Rgds,
Dan
Nov 20 '05 #4

Have a look at this discussion:

<http://www.google.de/groups?selm=bme...19.news.uni-be
rlin.de>


Ah, ok so it's not as easy as all that, I dont understand how to get the
value back out of the combobox...

I actually have a "Collection" of combobox's and I need to get the value
from the nth list item...

Help?

Thanks!
Dan

Nov 20 '05 #5
no hang on i think i may have it...

just need to figure out what the selected item is, hmm.

"Dan Keeley" <ma********@hotmail.com> wrote in message
news:05****************@newsfep4-winn.server.ntli.net...

Have a look at this discussion:

<http://www.google.de/groups?selm=bme...19.news.uni-be rlin.de>


Ah, ok so it's not as easy as all that, I dont understand how to get the
value back out of the combobox...

I actually have a "Collection" of combobox's and I need to get the value
from the nth list item...

Help?

Thanks!
Dan

Nov 20 '05 #6
Hi Dan,

In the light of this 'Collection' - could you rephrase your question?
Especially, what does 'nth' mean? Are there 'n' items and 'm' comboboxes? Etc,
etc..

Regards,
Fergus
Nov 20 '05 #7
Right ignore my other post i can't make it work!

Ok, I have a collection of combo boxes which i'm looking through. ComboItem
is the object stored in the combo box, which has a Name property and an
OptionValue property

I have this code:

Function GetValue(ByVal index As Integer)
Dim ACombo As ComboBox
ACombo = Me.List.Item(index) ' This gets the actual combo box from the
list
Dim a As Integer = ACombo.SelectedIndex
If a = -1 Then
'TODO Deal with the fact this is "Unselected"
a = 0
End If
Return i.Items.Item(a).OptionValue
End Function

Now it returns the correct selected item, however in the end it always
returns 0

Any ideas? Does that make any sense at all?!! I basically cannot seem to
access the optionValue which is a property of the custom object class which
is in the combobox!
"Fergus Cooney" <fi******@tesco.net> wrote in message
news:OY**************@tk2msftngp13.phx.gbl...
Hi Dan,

In the light of this 'Collection' - could you rephrase your question?
Especially, what does 'nth' mean? Are there 'n' items and 'm' comboboxes? Etc, etc..

Regards,
Fergus

Nov 20 '05 #8
Hi Dan,

Helping is tricky.
Return i.Items.Item(a).OptionValue
Where did 'i' jump up from? It tells me that the posted code isn't the
running code, and that's where the tricky comes in.

Whatever Items(a) gives, it's going to have to be cast into the correct
type so that you can see the OptionValue property.

How about writing a debug routine which will simply Console.WriteLine each
of the Items in the given ComboBox? You can call it with ACombo to determine
whether you can get <any> valid OptionValues out of it. Then worry about
getting the <correct> one.

Regards,
Fergus
Nov 20 '05 #9
Indeed, sorry about that, I mucked around with my values to make it easier
to understand for me as much as anything!

You're right though, I wasnt entering valid options into my list! I now
have this kind of thing(Actual code this time!)

Dim Coption As New ComboItem
Coption.Name = "Unacceptable"
Coption.OptionValue = 100
aComboBox.Items.Add(Coption)

Dim Coption2 As New ComboItem
Coption2.Name = "Major Non-Compliance"
Coption2.OptionValue = 50
aComboBox.Items.Add(Coption2)

Dim Coption3 As New ComboItem
Coption3.Name = "Minor Non-Compliance"
Coption3.OptionValue = 20
aComboBox.Items.Add(Coption3)

Dim Coption4 As New ComboItem
Coption4.Name = "Satisfactory"
Coption4.OptionValue = 9
aComboBox.Items.Add(Coption4)

and now it works! Thanks a lot, i'm certainly beginning to get my head
around all this stuff now and it's kinda clever !

Cheers,
Dan

PS: Is there any other better way i should be doing the above?

Once again thanks for the help. I now have a dynamic database driven form
with soon to have dynamic options in the combo's too :o)
"Fergus Cooney" <fi******@tesco.net> wrote in message
news:eI**************@tk2msftngp13.phx.gbl...
Hi Dan,

Helping is tricky.
Return i.Items.Item(a).OptionValue
Where did 'i' jump up from? It tells me that the posted code isn't the
running code, and that's where the tricky comes in.

Whatever Items(a) gives, it's going to have to be cast into the correct type so that you can see the OptionValue property.

How about writing a debug routine which will simply Console.WriteLine each of the Items in the given ComboBox? You can call it with ACombo to determine whether you can get <any> valid OptionValues out of it. Then worry about
getting the <correct> one.

Regards,
Fergus

Nov 20 '05 #10
Hi Dan,

While that will certainly work for a few items, here's a couple of
suggestions.

With the code that you have, you use Coption once and then discard it.
Then you declare and use Coption2, and so on. You could simply keep using
Coption each time. Coption = New ComboItem.

What I would do, though, is add a constructor to the ComboItem class

Class ComboItem
: : :
Public Sub New (ThisName As String, ThisOptionValue As Integer)
Name = ThisName
OptionValue = ThisOptionValue
End Sub
End Class

Then it can be initialised like so:
aComboBox.Items.Add (New ComboItem ("Unacceptable", 100))
aComboBox.Items.Add (New ComboItem ("Major Non-Comp", 50))
aComboBox.Items.Add (New ComboItem ("Minor Non-Comp", 20))
aComboBox.Items.Add (New ComboItem ("Satisfactory", 9))

Regards,
Fergus
Nov 20 '05 #11

Ah, Excellent thats exactly the sort of thing i should have been thinking
of.

I did try re-using Coption by the way, and it didnt work, I got the last
item i'd added 4 times.. This confused me a lot! strange.

Thanks for all your help tonight, I owe you a beer!

Dan

"Fergus Cooney" <fi******@tesco.net> wrote in message
news:eu**************@TK2MSFTNGP11.phx.gbl...
Hi Dan,

While that will certainly work for a few items, here's a couple of
suggestions.

With the code that you have, you use Coption once and then discard it.
Then you declare and use Coption2, and so on. You could simply keep using
Coption each time. Coption = New ComboItem.

What I would do, though, is add a constructor to the ComboItem class

Class ComboItem
: : :
Public Sub New (ThisName As String, ThisOptionValue As Integer)
Name = ThisName
OptionValue = ThisOptionValue
End Sub
End Class

Then it can be initialised like so:
aComboBox.Items.Add (New ComboItem ("Unacceptable", 100))
aComboBox.Items.Add (New ComboItem ("Major Non-Comp", 50))
aComboBox.Items.Add (New ComboItem ("Minor Non-Comp", 20))
aComboBox.Items.Add (New ComboItem ("Satisfactory", 9))

Regards,
Fergus

Nov 20 '05 #12
Hi Dan,

I caught myself before it was too late, but I almost recommended that very
mistake!!

The idea is that you can reuse Coption the <variable> but you have to give
it a New ComboItem each time.

This central heating makes me thirsty, so thanks for the beer! We're in
the same timezone so I'll see you in the Dog and Crown in half an hour!! ;-)

Regards,
Fergus
Nov 20 '05 #13

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

Similar topics

12
by: Eva | last post by:
Hi, I try to implement quick sort. I sort vectors by their first value. 10 2 3 4 9 3 5 6 10 4 5 6 must be 9 3 5 6 10 2 3 4 10 4 5 6 The prog works great on maybe 500 vectors, but I have an...
3
by: Martin Dew | last post by:
hi, I want to interogate the Quick Launch folder, looking at each icon and getting the image, and target that it fires when clicked. I can get to the folder and create a filelist of the icons, but...
2
by: Rudy | last post by:
Hello all! Have a quick question on drop down list. Need to make a year ddl, 1900 to 1987. Is there a quick way to do this. I'm not binding this, just loading it in the items collection. ...
0
by: Chrysan | last post by:
I have a popup window, which consist of 2 combobox. The second combobox's(cboCube) item collection will change based on the first combobox's(cboDatabase) event(selectedindex_changed) is fired. And,...
33
by: dembla | last post by:
Hey Frnds can anyone help me in this i need a program in 'c' PROGRAM to print NxN Matrix 9 1 8 1 2 3 2 7 3 as 4 5 6 6 4 5 7 8 9 in sorted form
0
by: WhatsPHP | last post by:
I like HTML Quick Form and think that it is a great tool.. but I still havent found any documentation that tells me how to use HTML Quick Forms with my own table and my own layout. Is this...
1
by: questionit | last post by:
Hi Experts I need to write a small stack very basic program. It will only do the following: - pop item - push item - count number of items in stack But difficulty i have is how to...
5
by: neehakale | last post by:
I know that heap sort,quick sort and merg sort are the faster sorting algoritms than the bubble sort,selection sort,shell sort and selection sort. I got an idea,in which situation we can use...
4
by: NvrBst | last post by:
A few quick questions if possible. 1 - If I have a "List<..myList" and set it as a datasouce for say ListBox1, then change items in "myList" is the correct/only way to update the ListBox with...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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.