High level view of the application is:
- Form1 displays client information in a DataGridView (pulled from a DB).
- I save the client's information from the DataGridView in properties located in a Client class.
- From Form1, the user can click a button that instantiates Form2 and allows the client's information to be modified.
- Form2's constructor has a Client object as a parameter. This object is what holds all the client's information from Form1. Using this object i can re-populate the fields that i want the user to be able to edit on Form2.
There is a table in the DataSource that holds all the case types (ie. CaseType1, CaseType2, CaseType3).
I then use a ComboBox and populate it with all the case types from the DataSource when the form is instantiated. My ComboBox settings are as follows:
DataSource: set to my CaseTypeBindingSource which has the columns and data i need. DisplayMember: The result of the query being used. ValueMember: The result of the query being used. (same as DisplayMember) SelectedValue: I have tried it with "none" and with the same value as DisplayMember and ValueMember.
Here's the problem:
At run-time, i want to be able to assign the client's case type that was brought over from Form1 as the item that is currently selected in the ComboBox (SelectedItem).
I could just assign the case type to a textbox and be done with it. But the idea is that i would like the form to show the user what the client's case type is, and allow him/her to change it by using the ComboBox.
The ComboBox name is CaseTypeComboBox. The object holding the case type information and its property is client.CaseType.
I've tried the following inside the constructor:
CaseTypeComboBox.SelectedItem = client.CaseType;
I've also tried creating a class variable in Form2 called origCaseType, assigning the client.CaseType value to the origCaseType class variable in the constructor. Then doing the following when the Form2_Load(...) event fires:
CaseTypeComboBox.SelectedValue = origCaseType;
Does anyone have any thoughts on this? Any similar experience?
Please let me know if anything needs clarification, any help is appreciated.
Thanks in advance!
TS
"Form2" Constructor:
public ModifyCase(Client client)
{
InitializeComponent();
CaseNumberTextBox.Text = client.CaseNumber;
LoadStatusComboBox(client.Status);
LoadIsClosedRadioButton(client.IsClosed);
LoadIsInStorageRadioButton(client.IsInStorage);
LastModifiedTextBox.Text = client.LastModified.ToString();
NotesTextBox.Text = client.Notes;
origCaseType = client.CaseType;
}
"Form2" Load event:
private void ModifyCase_Load(object sender, EventArgs e)
{
//Fills the ComboBox box with case types
this.case_typesTableAdapter1.Fill(this.testDataSet1.case_types);
//Attempts to set value for client's case type from Form1
CaseTypeComboBox.SelectedValue = origCaseType;
//Just to help me see what these variables are holding to figure
//out the problem...
MessageBox.Show(origCaseType);
MessageBox.Show(CaseTypeComboBox.SelectedIndex.ToString());
}