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