Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / October 2004

Tip: Looking for answers? Try searching our database.

strange problem with binding collection object to listbox control

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
David C - 16 Oct 2004 22:08 GMT
I have a business object with two public properties - "OrganizationID" and
"OrganizationName".  Pretty typical.  We will call it Organization.

And I have a collection object which is an arraylist that stores a
collection of the business object described above.  Let's call it
Organizations

I have a lstbox control.  So I bind it Organizations to the listbox control.

lstSelectedOrgs.DataSource = null;
lstSelectedOrgs.ValueMember = "OrganizationID";
lstSelectedOrgs.DisplayMember = "OrganizationName";
lstSelectedOrgs.DataSource = Organizations;

I initially populate the control.  Then I have a way to remove an item.  And
then I bind it again.

At some point, all of a sudden, what shows up in the list box looks like
this.

MyNameSpace.Organization
David C - 16 Oct 2004 22:12 GMT
Sorry, I didn't complete my post below before clicking the send button.
Here is a completed version

I have a business object with two public properties - "OrganizationID" and
"OrganizationName".  Pretty typical.  We will call it Organization.

And I have a collection object which is an arraylist that stores a
collection of the business object described above.  Let's call it
Organizations

I have a lstbox control.  So I bind it Organizations to the listbox control.

lstSelectedOrgs.DataSource = null;
lstSelectedOrgs.ValueMember = "OrganizationID";
lstSelectedOrgs.DisplayMember = "OrganizationName";
lstSelectedOrgs.DataSource = Organizations;

I initially populate the control.  Then I have a way to remove an item.  And
then I bind it again.

At some point, all of a sudden, what shows up in the list box looks like
this.

MyNameSpace.Organization
MyNameSpace.Organization
MyNameSpace.Organization
MyNameSpace.Organization
MyNameSpace.Organization

And the number of the items shown in the control matches what I have inside
the collection.  Then when I click on one of the items, it crashes.

Any ideas?
Sooraj PM - 17 Oct 2004 08:37 GMT
Hi

If OrganizationId and OrganizationName are declared as properties then it
will not crash. You might have declared these as public variables.

Regards

Sooraj
Microsoft Community Star

> Sorry, I didn't complete my post below before clicking the send button.
> Here is a completed version
[quoted text clipped - 29 lines]
>
> Any ideas?
Sijin Joseph - 18 Oct 2004 05:05 GMT
Set the valueMember and DisplayMember after setting the DataSource property

Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph

> Sorry, I didn't complete my post below before clicking the send button.
> Here is a completed version
[quoted text clipped - 29 lines]
>
> Any ideas?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.