"Al Reid" <ar*****@reidDASHhome.com> wrote in
news:#o**************@TK2MSFTNGP15.phx.gbl:
"TheGanjaMan" <th*********@somplace.invalid> wrote in message
news:Xn*************************@207.46.248.16... Hi all,
I'm pretty new to programming with vb.net. I'm stuck on a problem:
....
Any help would be appreciated.
Thanks...
The Add method expects a single object to be passed to it. If you
want to add a combo item and item data like you could in vb6 create a
ComboIItem class and pass an instance to the Add method.
=======================
Public Class ComboItem
' Declare the variable the property uses.
.... End Class
======================
Then you can add the Items and ItemData to the ComboBox using
Combobox1.Items.Add(New ComboItem("Canada", "1")
I hope this helps.
--
Al Reid
Thanks... I'm pretty new to OOP so I think I need time for the code in the
class to sink in.
I did put your code into a new class in my project and now my combobox
accepts the values I assign to it. but when I try to read the
combobox1.selectedvalue I still get nothing. What am I doing wrong?
I have the following code to fill the combobox:
Public Sub FillMenu()
Dim conn = DBConn()
Dim sqlstr As String = "select * from Form_Table"
Dim rs = DBrs(conn, sqlstr)
Do While rs.read
ComboBox1.Items.Add(New ComboItem(rs("form_name"), rs("T_id")))
Loop
conn.close()
End Sub
The above code works as it fills the combobox... but when I do this:
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
ComboBox1.SelectedIndexChanged
TextBox2.Text = ComboBox1.SelectedValue & " - " &
ComboBox1.SelectedItem
End Sub
I get en error and when I do this:
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
ComboBox1.SelectedIndexChanged
TextBox2.Text = ComboBox1.SelectedValue
End Sub
I get nothing... any ideas?
(Thanks very much for the example code...)