strange problem with binding collection object to listbox control

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
 
D

David C

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?
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top