To pass value from one form to another we have to add a property in the form from which we want to send data. To set property we have to write the following code. Let us say this is form2.
public int num
{
get
{
return 5;
}
set
{
num = value;
}
}
public int num1
{
get
{
return 15;
}
set
{
num1 = value;
}
}
The code above will return 5 when the property when it is called from form1. To call the property from form1 we have to write the collowing code in form1.
int n = form2.num;
Example
Here br is object of form2 (browse form).
frmBrowse br = new frmBrowse();
private void btnBrowse_Click(object sender, EventArgs e)
{
br.ShowDialog();
txtId.Text = br.num;
txtName.Text = br.num1;
panel1.Enabled = true;
}

Here form2 in Browse form. When any cell is clicked in data grid of this form the record will be transferred from this form to Record form (i.e. Form1).

Leave a Comment
2 Comments