I have a Windows Form Which Displays one record at a
time. The DataTable object which is bound to the Form
Controls only contains the record that is being
displayed. When I need to display a different record, any
changes in the current record are saved to an Access
Database, the DataTable's Row Collection is Cleared and
the New Record is read into the DataTable. (This is done
to ensure that when the User goes to view a record, they
get the most current version of that record).
The Problem I am having is that when the Windows Form
contains a ComboBox, when the form is initially loaded,
the First record is correctly displayed. However, as soon
as I move to another record, all of the controls are
blank, even when I move back to the original record. This
is not a case of the underlying DataTable not being
filled correctly, since while stepping through the code
in the debugger, I checked the DataTable and it contained
the correct information.
I have another form that using this same method to
display records, and it functions perfectly. The only
difference is that this form contains ComboBoxes, and the
Other form doesn't. When I remove the DataBinding
statements for the ComboBoxes, this form functions
correctly.
Ironically, I initially stored the data in XML files, and
this form functioned correctly.
Here is the Form Constructor:
public TestcaseEntry(C urrentUser p_User,
CurrentProject p_Project, string p_CaseSelection )
{
//
// Required for Windows Form
Designer support
//
InitializeCompo nent();
this.m_User = p_User;
this.m_Project = p_Project;
this.m_CaseSele ction = p_CaseSelection ;
this.m_TestType s = TestTypes.GetTy pes
();
this.m_TestType View = new DataView
(this.m_TestTyp es.TypeList);
this.m_TestType View.Sort = "Category";
this.m_Programs = Programs.GetPro gramList ();
this.m_CaseList = Testcases.GetCa seList
(p_CaseSelectio n);
this.m_RecordCo unt = this.m_CaseList .Count;
this.m_RecordIn dex = 0;
this.m_Testcase = new Testcases ();
this.m_Testcase .SetAuthorInfo (this.m_User.ID ,
this.m_User.Aut horString);
// Set the Datasource property for the Items
collection and bind this Program Control to the Testcase
Record
this.m_cboProgr am.DataSource =
this.m_Programs .Selections;
this.m_cboProgr am.DisplayMembe r = "Name";
this.m_cboProgr am.ValueMember = "ID";
this.m_cboProgr am.DataBindings .Add
("SelectedValue ",
this.m_Testcase .TestcaseList, "ProgramID" );
// Set the Datasource property for the Items
collection and bind this TestTypeCategor y Control to the
Testcase Record
this.m_cboTestT ypeCat.DataSour ce =
this.m_TestType s.CategoryList;
this.m_cboTestT ypeCat.DisplayM ember = "Name";
this.m_cboTestT ypeCat.ValueMem ber = "ID";
this.m_cboTestT ypeCat.DataBind ings.Add
("SelectedValue ",
this.m_Testcase .TestcaseList, "TestTypeCatego ry");
// Set the Datasource property for the Items
collection and bind this TestType Control to the Testcase
Record
this.m_cboTestT ype.DataSource =
this.m_TestType View;
this.m_cboTestT ype.DisplayMemb er = "Name";
this.m_cboTestT ype.ValueMember = "ID";
this.m_cboTestT ype.DataBinding s.Add
("SelectedValue ",
this.m_Testcase .TestcaseList, "TestTypeID ");
// Set the DataSource Properties for the Goto
Case List
this.cboCaseLis t.DataSource =
this.m_CaseList .Selections;
this.cboCaseLis t.DisplayMember = "ID";
this.cboCaseLis t.ValueMember = "ID";
// Bind the Textboxes to the Testcase Record
this.m_txtID.Da taBindings.Add
("Text",
this.m_Testcase .TestcaseList, "TestcaseID " );
this.m_txtAutho r.DataBindings. Add
("Text",
this.m_Testcase .TestcaseList, "AuthorStri ng" );
this.m_txtShort Description.Dat aBindings.Add
("Text",
this.m_Testcase .TestcaseList, "ShortDescripti on");
this.m_txtDescr iption.DataBind ings.Add
("Text",
this.m_Testcase .TestcaseList, "Descriptio n" );
this.m_txtExpRe s.DataBindings. Add
("Text",
this.m_Testcase .TestcaseList, "ExpectedResult " );
this.m_txtDataP rofile.DataBind ings.Add
("Text",
this.m_Testcase .TestcaseList, "DataProfil e" );
this.m_CurrentT estcase = (CurrencyManage r)
this.BindingCon text[this.m_Testcase .TestcaseList];
}
The Only solution I can think of right now is to not
perform the DataBind for the ComboBoxes, and everytime, I
get a new record, locate the appropriate entry in each of
these comboboxes, and when the value in the comboboxes is
changed by the user, to in code update the appropriate
field in the record. Is there another solution??????