By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,478 Members | 1,374 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,478 IT Pros & Developers. It's quick & easy.

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

P: n/a
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)....
--
Peter...
Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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/de...boxcontrol.asp
Ken

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

"Prabhudhas Peter" <Pr*************@discussions.microsoft.com> wrote in
message news:FE**********************************@microsof t.com...
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)....
--
Peter...
Nov 21 '05 #2

P: n/a
"Prabhudhas Peter" <Pr*************@discussions.microsoft.com> schrieb:
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
///

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

Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.