Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > Transfer data to another form
 

Transfer data to another form

I try to transfer data from a DataGridView from one form to another form. I have the following code. When I try to run it, it doesn't appear with any errors, but it also doesn't transfer the data I want it to do. Where in my code do I do somethin wrong?

Faktureringssystem.cd (form1) code:

private void dgrKunder_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
// Find den aktuelle row der er selected når der dobbeltklikkes.
CurrencyManager cm = this.BindingContext[dgrKunder.DataSource, dgrKunder.DataMember] as CurrencyManager;
if (cm != null)
{
DataRowView rowView = cm.Current as DataRowView;
if (rowView != null)
{
fakturasystemDataSet.KunderRow row = rowView.Row as fakturasystemDataSet.KunderRow;
if (row != null)
{
// Nu har vi row'en der skal editeres.
// Og vi starter din edit form op.
using (RetKunde ef = new RetKunde())
{
// Initialiserer din edit forms tekstfelter
// til de eksisterende data.
ef.Navn = row["Navn"].ToString();
ef.Adresse = row["Adresse"].ToString();

// Vi viser formen som en dialog, og tester hvilken
// knap brugeren har trykket på vha. DialogResult.
if (ef.ShowDialog() == DialogResult.OK)
{
// Hvis brugeren trykkede på OK sætter vi værdierne
// i Row'en til de værdier brugeren har tastet ind.
row["Navn"] = ef.Navn;
row["Adresse"] = ef.Adresse;

//opdaterer Adapteren
this.kunderTableAdapter.Update(this.fakturasystemDataSet.Kunder);
}
}
}
}
}

}

RetKunde.cs (form2) code:

public partial class RetKunde : Form
{
public RetKunde()
{
InitializeComponent();
}

public string Navn
{
get { return txtRetNavn.Text; }
set { txtRetNavn.Text = value; }
}

public string Adresse
{
get { return txtRetAdresse.Text; }
set { txtRetAdresse.Text = value; }
}

private void btnGemRetKunde_Click(object sender, EventArgs e)
{
this.DialogResult = (sender == btnGemRetKunde) ? DialogResult.OK : DialogResult.Cancel;
Close();
}

}

simsen  Friday, June 30, 2006 4:27 AM

There's lots of 'if' statements in there. Have you put in a breakpoint to see which one is failing ?

cgraus  Friday, June 30, 2006 4:35 AM

Hi cgraus

I had that problem in many hours........And theres nothing wrong with the code. I didn't thought of to make a brakepoint.....when I did, I saw I had put it the wrong place (a double clic and not on a button - which I tested it on).

So thank you very much....I try the next time to test on the right places ;-)

simsen  Friday, June 30, 2006 4:55 AM

There's lots of 'if' statements in there. Have you put in a breakpoint to see which one is failing ?

cgraus  Friday, June 30, 2006 4:35 AM

Hi cgraus

I had that problem in many hours........And theres nothing wrong with the code. I didn't thought of to make a brakepoint.....when I did, I saw I had put it the wrong place (a double clic and not on a button - which I tested it on).

So thank you very much....I try the next time to test on the right places ;-)

simsen  Friday, June 30, 2006 4:55 AM

*grin* Don't worry, I've had similar experiences myself. That's just how it goes, sometimes. Glad we got it sorted.

cgraus  Friday, June 30, 2006 4:58 AM

You can use google to search for other answers

Custom Search

More Threads

• Global Connection Object for small Windows Forms application
• TableAdapter.Fill Problems
• Octagone Style buttons and Form
• Changing cell value in DGV does not update value in DataSet Table
• datagridview add new row
• How To: How can I add a checkbox column to a datagrid without binding it to datatable?
• about DataGridView + EditingControl
• There are 2 forms i want to
• DBNull error
• User Change VS data bind change