Need ComboBox Property Like "ItemData" as in VB 6.0.

G

Guest

I need a ComboBox property like "ItemData" in VB.Net as in VB 6.0.
The Idea behind this question is, i've created a user control combo box in
vb.net with my own set of properties..now i want to store the data of a
column from the database into the Combo box with the corresponding ID field
(which is some other column of the same record)....
 
K

Ken Tucker [MVP]

Hi,

Databind the combobox.


Dim conn As SqlConnection

Dim strConn As String


Dim daCustomer As SqlDataAdapter

Dim ds As New DataSet

strConn = "Server = " & Environment.MachineName & ";"

strConn &= "Database = NorthWind;"

strConn &= "Integrated Security = SSPI;"

conn = New SqlConnection(strConn)



daCustomer = New SqlDataAdapter("Select * from Customers", conn)

daCustomer.Fill(ds, "Customers")

ComboBox2.DataSource = ds.Tables("Customers")

ComboBox2.DisplayMember = "CustomerID"


http://msdn.microsoft.com/library/d...ingcomboboxcheckedlistboxorlistboxcontrol.asp


Ken

----------------------------

message I need a ComboBox property like "ItemData" in VB.Net as in VB 6.0.
The Idea behind this question is, i've created a user control combo box in
vb.net with my own set of properties..now i want to store the data of a
column from the database into the Combo box with the corresponding ID field
(which is some other column of the same record)....
 
H

Herfried K. Wagner [MVP]

Prabhudhas Peter said:
I need a ComboBox property like "ItemData" in VB.Net as in VB 6.0.
The Idea behind this question is, i've created a user control combo box in
vb.net with my own set of properties..now i want to store the data of a
column from the database into the Combo box with the corresponding ID
field
(which is some other column of the same record)....

\\\
Dim p As New Person()
p.Name = "Pink Panther"
p.Age = 22
Me.ComboBox1.Items.Add(p)

' Test.
MsgBox(DirectCast(Me.ComboBox1.Items(0), Person).ToString())
..
..
..
Public Class Person
Private m_Name As String
Private m_Age As Integer

Public Property Name() As String
Get
Return m_Name
End Get
Set(ByVal Value As String)
m_Name = Value
End Set
End Property

Public Property Age() As Integer
Get
Return m_Age
End Get
Set(ByVal Value As Integer)
m_Age = Value
End Set
End Property

Public Overrides Function ToString() As String
Return Me.Name & " (" & Me.Age.ToString() & ")"
End Function
End Class
///

Alternatively, you can use a bound combobox:

\\\
With Me.ListBox1

' This can be an 'ArrayList' or array too, for example.
.DataSource = Database.FindPeople(...)
.DisplayMember = "Name"
.ValueMember = "Age"
End With
///
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Combobox ItemData ? 2
where ItemData in ComboBox? 7
ItemData 4
VB equivalent of Itemdata in Combo box 5
ItemData equivalent .NET 5
Newbie 7
Combobox in VB2005 11
Combo box 4

Top