472,992 Members | 3,259 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,992 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 1774
>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: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.