Hi All,
I am looking for "best-practices" to display the value of foreign-key in a BindingSource.
Sample data:
PetID---PetName---PetTypeID
1---Tom---1
2---Jerry---2
PetTypeID---PetType
1---Cat
2---Mouse
I have a Pet class and Pet form. The following code is on the Pet form to return data from the database as a Pet collection and bind the data:
private BindingSource PetBindingSource = new BindingSource();
PetBindingSource.DataSource = Pet.GetPets();
txtPetName.DataBindings.Add(new Binding("Text", PetBindingSource, "PetName"));
txtPetType.DataBindings.Add(new Binding("Text", PetBindingSource, "PetTypeID"));
With this current example, txtPetType will show the PetTypeID (1 or 2), but I want it to display the actual value (Cat or Mouse).
So, what are some best-practices to handle something like this? Add a new property to the Pet class? Join the two tables in the stored procedure to return the value? Other options?
Note: PetName is editable, while PetTypeID will be read-only in this instance, so I'd like to rule out a combo box.
Explanations, examples, reading resources would all be much appreciated!