473,406 Members | 2,954 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,406 software developers and data experts.

basic object question

Hi,

Having a mental block on this one. Have done it before but can't rack my
brain on how...

I have an object, with a bunch on property, and I add that object to a combo
box. I want the property '.fulladdress' to be the value that appears in the
drop downs text section.

How to I set that parameter to be the one shown inthe drop down

Dec 18 '05 #1
5 1794
>How to I set that parameter to be the one shown inthe drop down

Set the Combobox' DisplayMember property to "fulladdress".
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Dec 19 '05 #2
Hi Aussie,

I agree with Mattias, for the ComboBox control, we can use the
"DisplayMember" to specify which property used to bind to ListItem's Text
property, e.g:

Private Sub BindComboBox()
ComboBox1.DataSource = DataSet1.Tables("Suppliers")
ComboBox1.DisplayMember = "ProductName"
End Sub

Also, here is a kb article which provide detailed description on .net
winform databinding:

#Roadmap for Windows Forms data binding
http://support.microsoft.com/?id=313482

Hope helps. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| From: Mattias Sjögren <ma********************@mvps.org>
| Subject: Re: basic object question
| Date: Mon, 19 Dec 2005 01:41:19 +0100
| References: <OC**************@TK2MSFTNGP12.phx.gbl>
| X-Newsreader: Forte Agent 3.0/32.763
| MIME-Version: 1.0
| Content-Type: text/plain; charset=ISO-8859-1
| Content-Transfer-Encoding: 8bit
| Message-ID: <Oj**************@TK2MSFTNGP11.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.vb
| NNTP-Posting-Host: 85.8.3.112
| Lines: 1
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP11.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl microsoft.public.dotnet.languages.vb:309159
| X-Tomcat-NG: microsoft.public.dotnet.languages.vb
|
| >How to I set that parameter to be the one shown inthe drop down
|
| Set the Combobox' DisplayMember property to "fulladdress".
|
|
| Mattias
|
| --
| Mattias Sjögren [C# MVP] mattias @ mvps.org
| http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
| Please reply only to the newsgroup.
|

Dec 19 '05 #3
Hi,

The following code :

For Each pRow In dsName.Tables("Property").Rows

Dim oObject As New clsProperty

oObject.intPropertyId = pRow("Property_ID")

oObject.strProperty_Address1 = DBTextToString(pRow("Property_address1")) & "
" & DBTextToString(pRow("PostCode"))

oObject.strPropertyPrice = DBTextToString(pRow("Property_Price"))

cboProperty.DisplayMember = oObject.strProperty_Address1

cboProperty.Items.Add(oObject)

Next
Produces a drop down list that contains 'ProjectName.ClassName'

What am I doing wrong here ?


"Steven Cheng[MSFT]" <st*****@online.microsoft.com> wrote in message
news:f8*************@TK2MSFTNGXA02.phx.gbl...
Hi Aussie,

I agree with Mattias, for the ComboBox control, we can use the
"DisplayMember" to specify which property used to bind to ListItem's Text
property, e.g:

Private Sub BindComboBox()
ComboBox1.DataSource = DataSet1.Tables("Suppliers")
ComboBox1.DisplayMember = "ProductName"
End Sub

Also, here is a kb article which provide detailed description on .net
winform databinding:

#Roadmap for Windows Forms data binding
http://support.microsoft.com/?id=313482

Hope helps. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| From: Mattias Sjögren <ma********************@mvps.org>
| Subject: Re: basic object question
| Date: Mon, 19 Dec 2005 01:41:19 +0100
| References: <OC**************@TK2MSFTNGP12.phx.gbl>
| X-Newsreader: Forte Agent 3.0/32.763
| MIME-Version: 1.0
| Content-Type: text/plain; charset=ISO-8859-1
| Content-Transfer-Encoding: 8bit
| Message-ID: <Oj**************@TK2MSFTNGP11.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.vb
| NNTP-Posting-Host: 85.8.3.112
| Lines: 1
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP11.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl microsoft.public.dotnet.languages.vb:309159
| X-Tomcat-NG: microsoft.public.dotnet.languages.vb
|
| >How to I set that parameter to be the one shown inthe drop down
|
| Set the Combobox' DisplayMember property to "fulladdress".
|
|
| Mattias
|
| --
| Mattias Sjögren [C# MVP] mattias @ mvps.org
| http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
| Please reply only to the newsgroup.
|

Dec 19 '05 #4
Thanks for your respones Aussie,

The problems is that you didn't set the DisplayMember or ValueMember to the
correct string name of the Property you want to bind. Here is a simple
example which bind a combobox to an Array of custom class objects:

======custom class==========
Public Class CustomerClass
Private _id As Long
Private _name As String
Private _level As Integer

Public Sub New()

End Sub

Public Sub New(ByVal id As Long, ByVal name As String, ByVal level As
Integer)
_id = id
_name = name
_level = level

End Sub

Public Property ID() As Long
Get
Return _id
End Get

Set(ByVal Value As Long)
_id = Value
End Set
End Property

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

Public Property Level() As Integer
Get
Return _level
End Get
Set(ByVal Value As Integer)
_level = Value
End Set
End Property
End Class
==================================

=========databinding===========
Private Sub InputForm_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Bind_cbCustomer()

End Sub

Private Sub Bind_cbCustomer()

Dim customers() As CustomerClass
ReDim customers(15)
Dim i As Integer

For i = 1 To customers.Length

Dim cu As New CustomerClass
cu.ID = i
cu.Name = "Name_" & i
cu.Level = i Mod 5

customers(i - 1) = cu
Next
cbCustomers.DisplayMember = "Name"
cbCustomers.ValueMember = "ID"
cbCustomers.DataSource = customers
End Sub
========================

Hope helps. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


--------------------
| From: "Aussie Rules" <Au*********@nospam.nospam>
| References: <OC**************@TK2MSFTNGP12.phx.gbl>
<Oj**************@TK2MSFTNGP11.phx.gbl>
<f8*************@TK2MSFTNGXA02.phx.gbl>
| Subject: Re: basic object question
| Date: Mon, 19 Dec 2005 23:22:51 -0000
| Lines: 90
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
| X-RFC2646: Format=Flowed; Original
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
| Message-ID: <#2**************@TK2MSFTNGP11.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.vb
| NNTP-Posting-Host: ACBCEE63.ipt.aol.com 172.188.238.99
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP11.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl microsoft.public.dotnet.languages.vb:309325
| X-Tomcat-NG: microsoft.public.dotnet.languages.vb
|
| Hi,
|
| The following code :
|
| For Each pRow In dsName.Tables("Property").Rows
|
| Dim oObject As New clsProperty
|
| oObject.intPropertyId = pRow("Property_ID")
|
| oObject.strProperty_Address1 = DBTextToString(pRow("Property_address1"))
& "
| " & DBTextToString(pRow("PostCode"))
|
| oObject.strPropertyPrice = DBTextToString(pRow("Property_Price"))
|
| cboProperty.DisplayMember = oObject.strProperty_Address1
|
| cboProperty.Items.Add(oObject)
|
| Next
|
|
| Produces a drop down list that contains 'ProjectName.ClassName'
|
| What am I doing wrong here ?
|
|
|
|
| "Steven Cheng[MSFT]" <st*****@online.microsoft.com> wrote in message
| news:f8*************@TK2MSFTNGXA02.phx.gbl...
| > Hi Aussie,
| >
| > I agree with Mattias, for the ComboBox control, we can use the
| > "DisplayMember" to specify which property used to bind to ListItem's
Text
| > property, e.g:
| >
| > Private Sub BindComboBox()
| > ComboBox1.DataSource = DataSet1.Tables("Suppliers")
| > ComboBox1.DisplayMember = "ProductName"
| > End Sub
| >
| > Also, here is a kb article which provide detailed description on .net
| > winform databinding:
| >
| > #Roadmap for Windows Forms data binding
| > http://support.microsoft.com/?id=313482
| >
| > Hope helps. Thanks,
| >
| > Steven Cheng
| > Microsoft Online Support
| >
| > Get Secure! www.microsoft.com/security
| > (This posting is provided "AS IS", with no warranties, and confers no
| > rights.)
| >
| >
| > --------------------
| > | From: Mattias Sjögren <ma********************@mvps.org>
| > | Subject: Re: basic object question
| > | Date: Mon, 19 Dec 2005 01:41:19 +0100
| > | References: <OC**************@TK2MSFTNGP12.phx.gbl>
| > | X-Newsreader: Forte Agent 3.0/32.763
| > | MIME-Version: 1.0
| > | Content-Type: text/plain; charset=ISO-8859-1
| > | Content-Transfer-Encoding: 8bit
| > | Message-ID: <Oj**************@TK2MSFTNGP11.phx.gbl>
| > | Newsgroups: microsoft.public.dotnet.languages.vb
| > | NNTP-Posting-Host: 85.8.3.112
| > | Lines: 1
| > | Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP11.phx.gbl
| > | Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.languages.vb:309159
| > | X-Tomcat-NG: microsoft.public.dotnet.languages.vb
| > |
| > | >How to I set that parameter to be the one shown inthe drop down
| > |
| > | Set the Combobox' DisplayMember property to "fulladdress".
| > |
| > |
| > | Mattias
| > |
| > | --
| > | Mattias Sjögren [C# MVP] mattias @ mvps.org
| > | http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
| > | Please reply only to the newsgroup.
| > |
| >
|
|
|

Dec 20 '05 #5
Hi Aussie,

have you got any further process on this or does my suggestion in last
reply helps?
If there're anything else we can help, please feel free to post here.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| X-Tomcat-ID: 88200904
| References: <OC**************@TK2MSFTNGP12.phx.gbl>
<Oj**************@TK2MSFTNGP11.phx.gbl>
<f8*************@TK2MSFTNGXA02.phx.gbl>
<#2**************@TK2MSFTNGP11.phx.gbl>
| MIME-Version: 1.0
| Content-Type: text/plain
| Content-Transfer-Encoding: 7bit
| From: st*****@online.microsoft.com (Steven Cheng[MSFT])
| Organization: Microsoft
| Date: Tue, 20 Dec 2005 05:11:20 GMT
| Subject: Re: basic object question
| X-Tomcat-NG: microsoft.public.dotnet.languages.vb
| Message-ID: <d6**************@TK2MSFTNGXA02.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.vb
| Lines: 144
| Path: TK2MSFTNGXA02.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl microsoft.public.dotnet.languages.vb:309335
| NNTP-Posting-Host: tomcatimport2.phx.gbl 10.201.218.182
|
| Thanks for your respones Aussie,
|
| The problems is that you didn't set the DisplayMember or ValueMember to
the
| correct string name of the Property you want to bind. Here is a simple
| example which bind a combobox to an Array of custom class objects:
|
| ======custom class==========
| Public Class CustomerClass
| Private _id As Long
| Private _name As String
| Private _level As Integer
|
| Public Sub New()
|
| End Sub
|
| Public Sub New(ByVal id As Long, ByVal name As String, ByVal level As
| Integer)
| _id = id
| _name = name
| _level = level
|
| End Sub
|
| Public Property ID() As Long
| Get
| Return _id
| End Get
|
| Set(ByVal Value As Long)
| _id = Value
| End Set
| End Property
|
| Public Property Name() As String
| Get
| Return _name
| End Get
| Set(ByVal Value As String)
| _name = Value
| End Set
| End Property
|
| Public Property Level() As Integer
| Get
| Return _level
| End Get
| Set(ByVal Value As Integer)
| _level = Value
| End Set
| End Property
| End Class
| ==================================
|
|
|
| =========databinding===========
| Private Sub InputForm_Load(ByVal sender As System.Object, ByVal e As
| System.EventArgs) Handles MyBase.Load
|
| Bind_cbCustomer()
|
| End Sub
|
| Private Sub Bind_cbCustomer()
|
| Dim customers() As CustomerClass
| ReDim customers(15)
|
|
| Dim i As Integer
|
| For i = 1 To customers.Length
|
| Dim cu As New CustomerClass
| cu.ID = i
| cu.Name = "Name_" & i
| cu.Level = i Mod 5
|
| customers(i - 1) = cu
| Next
|
|
| cbCustomers.DisplayMember = "Name"
| cbCustomers.ValueMember = "ID"
| cbCustomers.DataSource = customers
|
|
| End Sub
| ========================
|
| Hope helps. Thanks,
|
| Steven Cheng
| Microsoft Online Support
|
| Get Secure! www.microsoft.com/security
| (This posting is provided "AS IS", with no warranties, and confers no
| rights.)
|
|
|
|
| --------------------
| | From: "Aussie Rules" <Au*********@nospam.nospam>
| | References: <OC**************@TK2MSFTNGP12.phx.gbl>
| <Oj**************@TK2MSFTNGP11.phx.gbl>
| <f8*************@TK2MSFTNGXA02.phx.gbl>
| | Subject: Re: basic object question
| | Date: Mon, 19 Dec 2005 23:22:51 -0000
| | Lines: 90
| | X-Priority: 3
| | X-MSMail-Priority: Normal
| | X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
| | X-RFC2646: Format=Flowed; Original
| | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
| | Message-ID: <#2**************@TK2MSFTNGP11.phx.gbl>
| | Newsgroups: microsoft.public.dotnet.languages.vb
| | NNTP-Posting-Host: ACBCEE63.ipt.aol.com 172.188.238.99
| | Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP11.phx.gbl
| | Xref: TK2MSFTNGXA02.phx.gbl microsoft.public.dotnet.languages.vb:309325
| | X-Tomcat-NG: microsoft.public.dotnet.languages.vb
| |
| | Hi,
| |
| | The following code :
| |
| | For Each pRow In dsName.Tables("Property").Rows
| |
| | Dim oObject As New clsProperty
| |
| | oObject.intPropertyId = pRow("Property_ID")
| |
| | oObject.strProperty_Address1 =
DBTextToString(pRow("Property_address1"))
| & "
| | " & DBTextToString(pRow("PostCode"))
| |
| | oObject.strPropertyPrice = DBTextToString(pRow("Property_Price"))
| |
| | cboProperty.DisplayMember = oObject.strProperty_Address1
| |
| | cboProperty.Items.Add(oObject)
| |
| | Next
| |
| |
| | Produces a drop down list that contains 'ProjectName.ClassName'
| |
| | What am I doing wrong here ?
| |
| |
| |
| |
| | "Steven Cheng[MSFT]" <st*****@online.microsoft.com> wrote in message
| | news:f8*************@TK2MSFTNGXA02.phx.gbl...
| | > Hi Aussie,
| | >
| | > I agree with Mattias, for the ComboBox control, we can use the
| | > "DisplayMember" to specify which property used to bind to ListItem's
| Text
| | > property, e.g:
| | >
| | > Private Sub BindComboBox()
| | > ComboBox1.DataSource = DataSet1.Tables("Suppliers")
| | > ComboBox1.DisplayMember = "ProductName"
| | > End Sub
| | >
| | > Also, here is a kb article which provide detailed description on .net
| | > winform databinding:
| | >
| | > #Roadmap for Windows Forms data binding
| | > http://support.microsoft.com/?id=313482
| | >
| | > Hope helps. Thanks,
| | >
| | > Steven Cheng
| | > Microsoft Online Support
| | >
| | > Get Secure! www.microsoft.com/security
| | > (This posting is provided "AS IS", with no warranties, and confers no
| | > rights.)
| | >
| | >
| | > --------------------
| | > | From: Mattias Sjögren <ma********************@mvps.org>
| | > | Subject: Re: basic object question
| | > | Date: Mon, 19 Dec 2005 01:41:19 +0100
| | > | References: <OC**************@TK2MSFTNGP12.phx.gbl>
| | > | X-Newsreader: Forte Agent 3.0/32.763
| | > | MIME-Version: 1.0
| | > | Content-Type: text/plain; charset=ISO-8859-1
| | > | Content-Transfer-Encoding: 8bit
| | > | Message-ID: <Oj**************@TK2MSFTNGP11.phx.gbl>
| | > | Newsgroups: microsoft.public.dotnet.languages.vb
| | > | NNTP-Posting-Host: 85.8.3.112
| | > | Lines: 1
| | > | Path:
TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP11.phx.gbl
| | > | Xref: TK2MSFTNGXA02.phx.gbl
| microsoft.public.dotnet.languages.vb:309159
| | > | X-Tomcat-NG: microsoft.public.dotnet.languages.vb
| | > |
| | > | >How to I set that parameter to be the one shown inthe drop down
| | > |
| | > | Set the Combobox' DisplayMember property to "fulladdress".
| | > |
| | > |
| | > | Mattias
| | > |
| | > | --
| | > | Mattias Sjögren [C# MVP] mattias @ mvps.org
| | > | http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
| | > | Please reply only to the newsgroup.
| | > |
| | >
| |
| |
| |
|
|

Dec 22 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: luis | last post by:
Are basic types (int, long, ...) objetcs or not? I read that in C# all are objects including basic types, derived from Object class. Then in msdn documentation says that boxing converts basic...
2
by: Janus | last post by:
Hell This is a very basic question i know :O Formerly I developed in VisualBasic 6.0 and when a project is started you can select different project types. But what exactly is an ActiveX DLL? -...
13
by: Pete | last post by:
I'm cross posting from mscom.webservices.general as I have received no answer there: There has been a number of recent posts requesting how to satisfactorily enable BASIC authorization at the...
6
by: pinorama123 | last post by:
I have an ASP.NET application that contains a few classes that I have built. One of my objects is a user object. I have a pretty basic question about how this would work. If I have multiple...
21
by: Roland | last post by:
The following issue is puzzling me: There are 2 ways of writing the code below: .... Dim fnt as Font = New Font(...) DrawString(myText, fnt,...) fnt.dispose(). or DrawString(myText, New...
4
by: MikeB | last post by:
I've been all over the net with this question, I hope I've finally found a group where I can ask about Visual Basic 2005. I'm at uni and we're working with Visual Basic 2005. I have some books, ...
14
by: MartinRinehart | last post by:
Working on parser for my language, I see that all classes (Token, Production, Statement, ...) have one thing in common. They all maintain start and stop positions in the source text. So it seems...
3
by: Tenowg | last post by:
Hey guys, I know this is probably a very easy, basic question, so feel free to direct me to a detailed answer. I have done some searches some some of the information I get is vague. In C#, the...
3
by: Scott Stark | last post by:
Hello, I'm trying to get a better handle on OOP programming principles in VB.NET. Forgive me if this question is sort of basic, but here's what I want to do. I have a collection of Employee...
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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...
0
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...

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.