1
Reply

Really need help on this irritating error on filling a textbox with data from a datagrid.

gerry veltjen

gerry veltjen

Apr 9 2009 7:38 AM
2.6k

Hello,

Hope someone can help me with this irritating error.

I have a form(Form1) with a textbox(TxtPcnummer) on it and a button(Button). When i click the button another form(Form2) opens with a datagrid(datagridview1).When i click on a cell the content need to show in the textbox of form1.This is my code:

public partial class Form1 : Form
{
public string i_pcnum;
public string pcnum
{
get { return i_pcnum; }
set { i_pcnum = value; }
}

public void UpdateTextboxen()
{

this.TxtPcnummer.Text = pcnum;
}
private void Button_Click(object sender, EventArgs e)
{
Form2 fm2 = new Form2();
fm2.Show();
}
}

public partial class Form2 : Form
{
public void dataGridView1_CellContentClick(object sender,DataGridViewCellEventArgs e)
{
string pcnummer = Convert.ToString (dataGridView1.CurrentRow.Cells ["PCNUMMER"].Value);
Form1 fm1 = new Form1();
fm1.pcnum = pcnummer;
fm1.UpdateTextboxen();

}

when i add a watch to the textbox TxtPcnummer the text value is giving me the right value but the text value is not showing in my form.So the textbox just stay empty when running the windows application.

greetz gerry


Answers (1)