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();
}
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)
{
Form1 frm1 = new Form1(txtID.Text, txtCN.Text, txtAdd.Text, dateTimePicker1.Text);
frm1.ShowDialog();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.