Data binding to collection problem

D

Derrick

I have a data binding problem that I just can't figure out. Here is the
scenario:
objects:
cTeam:
- <Properties>: <type>
Name: String;
Member: cMember
and other properties of basic data types
cMember
- <Properties>: <type>
fName: String;
lName: String;
and other properties of basic types
colTeam is a collection of cTeams.
colMember is a collection of cMembers

I am trying to display them with these controls:
- a list box that is bound to the colTeam
- 2 text boxes to show fName and lName
- a combo box that shows the selected member from the colMembers

When the form loads, I call my 'Public Sub initiallizeBinding()' code
<snip>
lstTeams.DataSource = mTeams
cboMembers.DataSource = g_Members
txtName.DataBindings.Add("text", mTeams, "Name")
cboMembers.DataBindings.Add("SelectedItem", mTeams, "Member")
bmb = Me.BindingContext(mTeams)
</snip>
When I select an item from the list box, the proper data is displayed in the
text boxes, but the combo box displays the first item in it's list. When I
move to another item in the list, that improper value that was in the combo
box overwrites the value in the team's Member property.

If I change the value in the combobox and save the object, the proper data
is stored in the data base and the object reflects the proper data. Then,
when I leave this record and return, the proper data is displayed.

I am absoluted Flummoxed. Any help would be appreciated.

Derrick
 
D

Derrick

Do I get points for answering my own post, or do I just get one of those 'I
am a dummy' bumper stickers?

To solve the problem, I modified the intiallizeBindings method:

<added Lines>
cboMembers.ValueMember = "ID"
cboMembers.DisplayMember = "FullName"
</added Lines>

and I replaced this

cboMembers.DataBindings.Add("SelectedItem", mTeams, "LeagueMember")

with this

cboMembers.DataBindings.Add("SelectedValue", mTeams, "Member.ID")

Sorry for the waste of posting space...

Derrick
 

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