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

basic object question

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
>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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.