473,395 Members | 1,969 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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

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
2 4007
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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Colleyville Alan | last post by:
I am constructing a SQL command from a function. Some code builds the WHERE clause in a looping structure and passes that as an argument to the SQL-building function. But the results do not...
2
by: google | last post by:
Hello everyone, I am having an issue using the "Multi Select" option in a list box in MS Access 2003. I am making a form that users can fill out to add an issue to the database. Each issue can...
8
by: Dan | last post by:
Is there any way to assign a tag value to each item in a listbox?
1
by: Andrew Robinson | last post by:
Woundering if anyone else has had issues with ConvertEmptyStringToNull="false" ? I have a custom data class and am passing values to it via an ODS. On my insert, if the bound text box is empty...
3
by: PW | last post by:
Hi, One of our clients is getting that error when they are trying to save a record but I can not duplicate it here. The data is on another PC and is linked to two workstations. The code...
12
by: micarl | last post by:
How would i print a report based on criteria selected from several Combo Boxes as well as multiple Multi Select List Boxes, that are located on the same form? I can get one Multi List Box, just...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.