473,508 Members | 2,389 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Combo box

Kay
Hi all,

Wondering is there a way to work with .net's combo box like in VB 6's with
the ItemData property? Coz I want to store 2 values for each item in the
combo....

Thanks!

Kay
Nov 21 '05 #1
4 1570
Each item in a .net combo box is an object therefore you can store a 1000
values per item if you really wanted too. .Net is OOP.

RR

"Kay" <kk@micxsoft.com> wrote in message
news:OV**************@tk2msftngp13.phx.gbl...
Hi all,

Wondering is there a way to work with .net's combo box like in VB 6's with
the ItemData property? Coz I want to store 2 values for each item in the
combo....

Thanks!

Kay

Nov 21 '05 #2
You can store any object you like in a combo box, so long as you
implement the ToString() method, the return value from that is what will
get displayed to the user.

For example

Private Sub FillComboMethod()

For i As Integer = 1 To 10

Dim objItem As New MyComboClass
objItem.DisplayText = "Item " & i.ToString()

ComboBox1.Items.Add(objItem)

Next

End Sub

Public Class MyComboClass

Private m_DisplayText As String
Private m_SomeOtherInfo As Integer
Private m_SomeOtherObject As Object

Public Property DisplayText() As String
Get
Return m_DisplayText
End Get
Set(ByVal Value As String)
m_DisplayText = Value
End Set
End Property

Public Property SomeOtherObject() As Object
Get
Return m_SomeOtherObject
End Get
Set(ByVal Value As Object)
m_SomeOtherObject = Value
End Set
End Property

Public Property SomeOtherInfo() As Integer
Get
Return m_SomeOtherInfo
End Get
Set(ByVal Value As Integer)
m_SomeOtherInfo = Value
End Set
End Property

Public Overrides Function ToString() As String
Return DisplayText
End Function

End Class

Kay wrote:
Hi all,

Wondering is there a way to work with .net's combo box like in VB 6's with
the ItemData property? Coz I want to store 2 values for each item in the
combo....

Thanks!

Kay

Nov 21 '05 #3
"Kay" <kk@micxsoft.com> schrieb:
Wondering is there a way to work with .net's combo box like in VB 6's with
the ItemData property? Coz I want to store 2 values for each item in the
combo....


See:

<URL:http://groups.google.de/group/microsoft.public.dotnet.languages.vb.upgrade/msg/90ca44e9479e5bd7>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #4
Kay
Hi James and Herfried,

Thank you very much for your code, I've tried both of them but have few
questions...(sorry I'm an OO newbie)

What I want to do is, show a "display field" in the combo box and hide the
key so I can save/update the DB later, I've changed the variables name in
the following code to make our disscussion easier.
>>>>>>>>> Private Sub frmTest_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim p As New ComboItem
Dim oSqlCmd As SqlCommand = New SqlCommand("Select * from Campaign
order by Campaign_Title")

oSqlCmd.Connection = CCMSConn
CCMSConn.Open()
theReader = oSqlCmd.ExecuteReader

Do While theReader.Read
p.Display = theReader("Campaign_Title").ToString
p.Hide = theReader("Campaign_Key").ToString
Me.ComboBox1.Items.Add(p)
Loop

CCMSConn.Close()
theReader.Close()

End Sub

Public Class ComboItem
Private DisplayField As String
Private HideField As String

Public Property Display() As String
Get
Return DisplayField
End Get
Set(ByVal Value As String)
DisplayField = Value
End Set
End Property
Public Property Hide() As Integer
Get
Return HideField
End Get
Set(ByVal Value As Integer)
HideField = Value
End Set
End Property
Public Overrides Function ToString() As String
Return Me.Display & " " & Me.Hide
End Function
End Class>>>>

So my questions are:
1) Can I only show one value in the combo box and hide the "Key"?
(Coz I want to keep the combo box compact)
2) How do I access the Key of the selected item? In Herfried's code he
has:
MsgBox(DirectCast(Me.ComboBox1.Items(0), ComboItem).ToString()
However I tried to modify this line but without luck....

Thanks in advance guys!

Kay

"Kay" <kk@micxsoft.com> wrote in message
news:OV**************@tk2msftngp13.phx.gbl... Hi all,

Wondering is there a way to work with .net's combo box like in VB 6's with
the ItemData property? Coz I want to store 2 values for each item in the
combo....

Thanks!

Kay

Nov 21 '05 #5

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

Similar topics

3
4287
by: vgrssrtrs | last post by:
<html> <head> <script language="JavaScript"> <!-- /* *** Multiple dynamic combo boxes *** by Mirko Elviro, 9 Mar 2005 *** ***Please do not remove this comment
4
4246
by: Heather | last post by:
Hi I am desparately looking for advice in relation to storing the results after selecting items from two combo boxes on a Referral form. The first combo box 'ctl Type' displays a full list of...
6
3536
by: Support4John | last post by:
a2k (9.0.6926) SP-3 Jet 4.0 SP-7 I have a form with combo box field that allows the user to select from the combo box or type in the field value that may or maynot be in the combo box field. ...
2
2147
by: Jeff Mason | last post by:
I'm observing some strange behavior when I use a bound combo box in conjunction with the combo's anchor property. I define a form which contains just a textbox and a combo box. The text box is...
3
3623
by: hmiller | last post by:
Hey everyone, I am having a hell of a time trying to set this menu system up. Here's what I'm trying to do. Combo Box One; is populated by names under properties "row source" "Phase 1"...
9
6741
by: Edwinah63 | last post by:
Hi everyone, Please let there be someone out there who can help. I have two BOUND combo boxes on a continuous form, the second being dependent on the first. I have no problem getting the...
2
2427
by: kiranmn75 | last post by:
I want to dynamically populate a combo box through javascript. Data is coming from a array. Sometimes data list may contain items in excess of 2000. Explorer takes more than 5 seconds to...
6
3667
by: Dave | last post by:
I want to put the information that the user selects in my combo boxes into a subform that lies on the same form as the combo boxes. Thanks for your help already, Dave
2
7016
by: biganthony via AccessMonster.com | last post by:
Hi, I decided to install Office 2003 Service Pack 3 on my home computer to test (in full knowledge that there may be some issues with it). After installation, I have noticed that with a small...
0
7224
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,...
1
7038
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...
0
7493
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
5625
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4706
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...
0
3192
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...
0
3180
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
763
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
415
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.