strange problem with binding collection object to listbox control

  • Thread starter Thread starter David C
  • Start date Start date
D

David C

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
 
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?
 
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
 
Back
Top