By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,136 Members | 1,087 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,136 IT Pros & Developers. It's quick & easy.

DataBinding Issue with ComboBox

P: n/a
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(CurrentUser p_User,
CurrentProject p_Project, string p_CaseSelection)
{
//
// Required for Windows Form
Designer support
//
InitializeComponent();

this.m_User = p_User;
this.m_Project = p_Project;
this.m_CaseSelection = p_CaseSelection;

this.m_TestTypes = TestTypes.GetTypes
();
this.m_TestTypeView = new DataView
(this.m_TestTypes.TypeList);
this.m_TestTypeView.Sort = "Category";

this.m_Programs = Programs.GetProgramList ();

this.m_CaseList = Testcases.GetCaseList
(p_CaseSelection);
this.m_RecordCount = this.m_CaseList.Count;
this.m_RecordIndex = 0;

this.m_Testcase = new Testcases ();

this.m_Testcase.SetAuthorInfo (this.m_User.ID,
this.m_User.AuthorString);

// Set the Datasource property for the Items
collection and bind this Program Control to the Testcase
Record
this.m_cboProgram.DataSource =
this.m_Programs.Selections;
this.m_cboProgram.DisplayMember = "Name";
this.m_cboProgram.ValueMember = "ID";
this.m_cboProgram.DataBindings.Add
("SelectedValue",
this.m_Testcase.TestcaseList, "ProgramID");

// Set the Datasource property for the Items
collection and bind this TestTypeCategory Control to the
Testcase Record
this.m_cboTestTypeCat.DataSource =
this.m_TestTypes.CategoryList;
this.m_cboTestTypeCat.DisplayMember = "Name";
this.m_cboTestTypeCat.ValueMember = "ID";
this.m_cboTestTypeCat.DataBindings.Add
("SelectedValue",
this.m_Testcase.TestcaseList, "TestTypeCategory");

// Set the Datasource property for the Items
collection and bind this TestType Control to the Testcase
Record
this.m_cboTestType.DataSource =
this.m_TestTypeView;
this.m_cboTestType.DisplayMember = "Name";
this.m_cboTestType.ValueMember = "ID";
this.m_cboTestType.DataBindings.Add
("SelectedValue",
this.m_Testcase.TestcaseList, "TestTypeID");

// Set the DataSource Properties for the Goto
Case List
this.cboCaseList.DataSource =
this.m_CaseList.Selections;
this.cboCaseList.DisplayMember = "ID";
this.cboCaseList.ValueMember = "ID";

// Bind the Textboxes to the Testcase Record
this.m_txtID.DataBindings.Add
("Text",
this.m_Testcase.TestcaseList, "TestcaseID" );
this.m_txtAuthor.DataBindings.Add
("Text",
this.m_Testcase.TestcaseList, "AuthorString" );
this.m_txtShortDescription.DataBindings.Add
("Text",
this.m_Testcase.TestcaseList, "ShortDescription");
this.m_txtDescription.DataBindings.Add
("Text",
this.m_Testcase.TestcaseList, "Description" );
this.m_txtExpRes.DataBindings.Add
("Text",
this.m_Testcase.TestcaseList, "ExpectedResult" );
this.m_txtDataProfile.DataBindings.Add
("Text",
this.m_Testcase.TestcaseList, "DataProfile" );

this.m_CurrentTestcase = (CurrencyManager)
this.BindingContext[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??????

Nov 15 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.