K
Kay
Hi All,
A week ago I posted a question regarding how to store 2 value (but display
1) in an combo box item, I can do it quite easily thru the itemdata property
in VB6 but this is not avaliable in .net, James and Herfried provided a
sample code as follow, I have few more questions after the code :
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 ClassSo 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....
Any suggestions are welcome! Thanks a lot guys!
Kay
A week ago I posted a question regarding how to store 2 value (but display
1) in an combo box item, I can do it quite easily thru the itemdata property
in VB6 but this is not avaliable in .net, James and Herfried provided a
sample code as follow, I have few more questions after the code :
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 ClassSo 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....
Any suggestions are welcome! Thanks a lot guys!
Kay