473,769 Members | 2,063 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1213
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********@hot mail.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=bme 0qq%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********@hot mail.com> wrote in message
news:05******** ********@newsfe p4-winn.server.ntl i.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(in dex) ' This gets the actual combo box from the
list
Dim a As Integer = ACombo.Selected Index
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******** ******@tk2msftn gp13.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.WriteLi ne 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 = "Unacceptab le"
Coption.OptionV alue = 100
aComboBox.Items .Add(Coption)

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

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

Dim Coption4 As New ComboItem
Coption4.Name = "Satisfacto ry"
Coption4.Option Value = 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******** ******@tk2msftn gp13.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.WriteLi ne 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

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

Similar topics

12
2925
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 "Aborted(core
3
2632
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 cannot seem to find where to go from there, can anyone help ? string dirPath = Path.Combine(System.Environment.GetEnvironmentVariable(Environment.SpecialFolder.ApplicationData),@"Microsoft\Internet Explorer\Quick Launch");
2
1108
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. Thanks!!! Rudy
0
994
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, I do have write such code in code-behind as follow: Private Sub cboDatabase_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboDatabase.SelectedIndexChanged Dim strAdomdConnectionString As String Try
33
3438
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
1408
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 possible? Instead of the default positioning of form items the way it is done in HTML Quick forms? Thanks WhatsPHP
1
1705
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 implement it using Ms Access - form ?
5
16635
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 bubble sort(use when we have to 100 items: bubble sort is effective),shell sort is effective when one has to sort near abt 5000 items..selection sort is effective for sorting 1000 items...and more than 1000 and less than 5000 items if u have to sort use...
4
1283
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 the following? ListBox1.DataSource = null; ListBox1.DataSource = myList; 2 - BindingList<...is the same as List<...except when it is set as
0
9579
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
10032
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9979
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
9849
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7393
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6661
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
5293
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...
0
5433
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3948
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

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.