473,789 Members | 2,352 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4044
Hi,

Databind the combobox.
Dim conn As SqlConnection

Dim strConn As String
Dim daCustomer As SqlDataAdapter

Dim ds As New DataSet

strConn = "Server = " & Environment.Mac hineName & ";"

strConn &= "Database = NorthWind;"

strConn &= "Integrated Security = SSPI;"

conn = New SqlConnection(s trConn)

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

daCustomer.Fill (ds, "Customers" )

ComboBox2.DataS ource = ds.Tables("Cust omers")

ComboBox2.Displ ayMember = "CustomerID "
http://msdn.microsoft.com/library/de...boxcontrol.asp
Ken

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

"Prabhudhas Peter" <Pr************ *@discussions.m icrosoft.com> wrote in
message news:FE******** *************** ***********@mic rosoft.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.m icrosoft.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.It ems.Add(p)

' Test.
MsgBox(DirectCa st(Me.ComboBox1 .Items(0), Person).ToStrin g())
..
..
..
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.FindPe ople(...)
.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
3013
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 always execute as I envisioned they should. When I trap the finished SQL statement in the Immediates window and paste it to a query SQL window, I can see in the QBE why I am not getting what I want. Basically, I want the QBE window to have the OR...
2
3041
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 be associated with multiple categories. I have an "Issue," "IssueCategory," and "Category" in the database (among other tables). The form has a subform in it which is tied to the "IssueCategory" table. The main form is tied to the "Issue"...
8
8764
by: Dan | last post by:
Is there any way to assign a tag value to each item in a listbox?
1
2431
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 an empty string or "" is passed to my data object. On an update, an empty string is converted to null. The insert does not use the ConvertEmptyStringToNull="false" property and works the way I was hoping. Setting this property on the update...
3
9559
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 (listed below) is just saving interests selected from a multi-list list box. I've never seen that error message before. Any ideas? What does it
12
4047
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 not several, to report using this code i found - Private Sub cmdPreview_Click()
0
9656
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10386
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10131
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9003
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7522
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6752
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5542
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4081
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2899
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.