Losing data

  • Thread starter Thread starter katie
  • Start date Start date
K

katie

Not sure how to explain this problem so here it goes... I have two forms and
I want to copy data from one form to load into another. Now this seems to be
working but the problem is the various controls seem to be populated before
the bindingcontext is finished. Therefore erasing my preload data.

How can I load this data into the new form without it being lost?


private void RegForm_Load(object sender, System.EventArgs e)
{
FillDataSets(); // goes into bindingcontext addnew

if(tFormStateStored != 0)
{
tFormStateStored = 0;
txtBoxCompany.Text = tCompany;
txtBoxAddress.Text = tAddress;
txtBoxCity.Text = tCity;
txtBoxStateProvince.Text = tState;
txtBoxZip.Text = tZip;
txtBoxPhone.Text = tPhone;
txtBoxEmail.Text = tEmail;
}

}

private void saveCreateCopy_Click(object sender, System.EventArgs e)
{
// copy some data...
tFormStateStored = 1;
tCompany = txtBoxCompany.Text;
tAddress = txtBoxAddress.Text;
tCity = txtBoxCity.Text;
tState = txtBoxStateProvince.Text;
tZip = txtBoxZip.Text;
tPhone = txtBoxPhone.Text;
tEmail = txtBoxEmail.Text;

// load a new form
RegForm newMDIChild = new RegForm();
newMDIChild.LoadCompanyID = 0;
// Set the Parent Form of the Child window.
newMDIChild.MdiParent = this.ParentForm;
// Display the new form.
newMDIChild.Show();
}


Kate S.
 
Hi Katie,

So if I understand you correctly, you're trying to open a new form and
populate it with data from your current form?

In the code sample you've provided I can't see how you've put the values
into the new form, perhaps you could post that part of your code as well?
Also, it sounds like you're using DataBinding. What is your form bound to?
(DataTable, or a custom type?)

Regards,
Matt Garven
 
Hi Matt,



Yes, I'm trying to copy some values out of an existing form automatically. I
do know the code to copy and paste the values from one form to the other
works if I tie the code to "paste" to say a button click. I just can get it
to work without having some user interaction.

my form is bound to a dataset / datatable


private static int tFormStateStored;
private static string tCompany;
private static string tAddress;
private static string tCity;
private static string tState;
private static string tZip;
private static string tPhone;
private static string tEmail;


private void RegForm_Load(object sender, System.EventArgs e)
{
FillDataSets(); // goes into bindingcontext addnew

if(tFormStateStored != 0)
{
tFormStateStored = 0;
txtBoxCompany.Text = tCompany;
txtBoxAddress.Text = tAddress;
txtBoxCity.Text = tCity;
txtBoxStateProvince.Text = tState;
txtBoxZip.Text = tZip;
txtBoxPhone.Text = tPhone;
txtBoxEmail.Text = tEmail;
}

}

private void saveCreateCopy_Click(object sender, System.EventArgs e)
{
// copy some data...
tFormStateStored = 1;
tCompany = txtBoxCompany.Text;
tAddress = txtBoxAddress.Text;
tCity = txtBoxCity.Text;
tState = txtBoxStateProvince.Text;
tZip = txtBoxZip.Text;
tPhone = txtBoxPhone.Text;
tEmail = txtBoxEmail.Text;

// load a new form
RegForm newMDIChild = new RegForm();
newMDIChild.LoadCompanyID = 0;
// Set the Parent Form of the Child window.
newMDIChild.MdiParent = this.ParentForm;
// Display the new form.
newMDIChild.Show();
}


public void FillDataSets()
{
dsRegistration1.EnforceConstraints = false;
dsRegistration1.Clear();
int rowCount = 0;
try
{
// open connection
this.sqlConnection1.Open();
// called for first record and is the default if not coming from a search
result
if(this._LoadCompanyID != 0)
{
this.tblAttendeesDA.SelectCommand.Parameters["@ID"].Value =
this._LoadCompanyID;
this._LoadCompanyID = 0;
}
else
{
this.tblAttendeesDA.SelectCommand.Parameters["@ID"].Value = 0;
this._LoadCompanyID = 0;
}
rowCount = this.tblAttendeesDA.Fill(dsRegistration1);
}
catch(System.Exception fillException)
{
System.Windows.Forms.MessageBox.Show(fillException.ToString());
}
finally
{
dsRegistration1.EnforceConstraints = true;
if( sqlConnection1.State == ConnectionState.Open)
{
sqlConnection1.Close();
}
}
if(rowCount <= 0)
{
this.GoInToAddMode();
}
}

public void GoInToAddMode()
{
try
{
this.BindingContext[dsRegistration1,"tblAttendees"].AddNew();
txtBoxCompany.Focus();
}
catch (System.Exception eEndEdit)
{
System.Windows.Forms.MessageBox.Show(eEndEdit.Message);
}
}



Kate S
 
Back
Top