Computing.Net > Forums > Programming > VB.NET ListBox DisplayMember

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

VB.NET ListBox DisplayMember

Reply to Message Icon

Name: Urkle10
Date: February 6, 2006 at 12:27:36 Pacific
OS: Windows XP
CPU/Ram: P4 3.0 GHz
Comment:

IDE: Microsoft Visual Studio .NET 2003
Language: Visual Basic .NET 2003

I am using a resource DLL to access an external database via OLE/COM. There is very little documentation aside from what methods are available and I do not have access to the source code. For all intents and purposes, each database item is returned as a DBobject collection.

I have a project wherein I created a ListBox control called Box. In my application, I add items to the list as follows.

Dim List As DBobject = anExistingCollection
Dim Item As DBobject
For Each Item In List
    Box.Items.Add(Item)
Next

From the Object Explorer, I found that there is a property defined in the DLL as follows.

Public Overridable Default Property [Property](Optional ByVal Type As Object = Nothing, Optional ByVal Index As Object = Nothing) As Object

In the code snippet below, I get the selected item and set a label control text value to the name of the DBobject since the "Property" property returns the name of the object by default.

Dim tempDBobject As DBobject
tempDBobject = Box.SelectedItem
Label1.Text = tempDBobject.Property

I set the DisplayMember of the ListBox to "Property" in the design view. When the ListBox is populated, every item is listed as being "System.__ComObject" but the Box.SelectedItems method returns the proper name value to be displayed in Label1.

I even tried the following as the DisplayMember in the design view with identical results. (Note that PropertyGet("Name") is another method to obtain the name value.)

Property
[Property]
"Property"
PropertyGet("Name")

I wrote a sample program with a class of my own design with a property that returned a String as an Object for the DisplayMemeber. It worked flawlessly. Does anyone have any suggestions as to why the proper text isn't being displayed in the ListBox for my real application? Thanks!

Urkle10



Sponsored Link
Ads by Google

Response Number 1
Name: Urkle10
Date: February 9, 2006 at 07:44:21 Pacific
Reply:

It turns outs that the DisplayMember and ValueMember properties are only used if the ListBox DataSource is set to an object that implements the IList interface. Since I added items individually using the Add method instead of setting the DataSource directly, the ListBox ignored DisplayMember and ValueMember.

Urkle10


0
Reply to Message Icon

Related Posts

See More


Registry change in batch ... Popup - javaScript



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: VB.NET ListBox DisplayMember

Printer paper collection in VB.NET www.computing.net/answers/programming/printer-paper-collection-in-vbnet/11265.html

How do I hide a form on load vb.net www.computing.net/answers/programming/how-do-i-hide-a-form-on-load-vbnet/4597.html

Vb .net www.computing.net/answers/programming/vb-net/13338.html