0

How to transfer the data of the second row of DataGridView to a label that is in another form?

Form1

  public partial class Form1 : Form
  {    
    public string IDD { get; set; }
    public string CN { get; set; }
    public string ADD { get; set; }
    public string TIME { get; set; }

    public Form1()
    {
        InitializeComponent();            
    }

    private void panel1_MouseDoubleClick(object sender, MouseEventArgs e)
    {
        Form4 frm4 = new Form4();

        frm4.IDDD = ClientID.Text;
        frm4.CNN = ClientName.Text;
        frm4.ADDD = ClientAdd.Text;
        frm4.TIMEE = ClientTime.Text;
        frm4.ShowDialog();            
    }
  }

Form2

 private void btnBack_Click(object sender, EventArgs e)
 {

    Form1 frm1 = new Form1();

    frm1.IDD = txtID.Text;
    frm1.CN = txtCN.Text;
    frm1.ADD = txtAdd.Text;
    frm1.TIME = dateTimePicker1.Text;
    
    frm1.lblID2.Text = this.dataGridView1.CurrentRow.Cells[0].Value.ToString();
    
    frm1.ShowDialog(); 
 }
ɐsɹǝʌ ǝɔıʌ
  • 4,440
  • 3
  • 35
  • 56
  • Does this answer your question? [Communicate between two windows forms in C#](https://stackoverflow.com/questions/1665533/communicate-between-two-windows-forms-in-c-sharp) – JohnG Jan 19 '22 at 01:21

1 Answers1

0

You can change default constructor in Form1:

public partial class Form1 : Form
{

    //notice: don't use UPPERCASE for naming properties, use PascalCase
    //example: public string Idd { get; set; }

    public string IDD { get; set; }
    public string CN { get; set; }
    public string ADD { get; set; }
    public string TIME { get; set; }

    public Form1(string idd, string cn, string add, string time, string dgwValue)
    {
        InitializeComponent();
        IDD = idd;
        CN = cn;
        ADD = add;
        TIME = time;
        this.lblID2.Text = dgwValue;
    }
}

Form2:


private void btnBack_Click(object sender, EventArgs e)
{
    string dgwValue = this.dataGridView1.CurrentRow.Cells[0].Value.ToString();
    Form1 frm1 = new Form1(txtID.Text, txtCN.Text, txtAdd.Text, dateTimePicker1.Text, dgwValue);
    frm1.ShowDialog();   
}

Aarnihauta
  • 441
  • 3
  • 10