Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / February 2005

Tip: Looking for answers? Try searching our database.

Losing data

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
katie - 11 Feb 2005 21:05 GMT
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.
Matt Garven - 14 Feb 2005 01:41 GMT
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

> 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
[quoted text clipped - 43 lines]
>
> Kate S.
katie - 14 Feb 2005 20:01 GMT
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

> Hi Katie,
>
[quoted text clipped - 8 lines]
> Regards,
> Matt Garven

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.