Pass value between two datagridview from two other forms without closing the form

  • //Write this at your first form button click to open the second form

    frmSelectSpecialCodes frm = new frmSelectSpecialCodes();
    frm.ItemCode = dgvCart.SelectedRows[0].Cells[1].Value.ToString(); 
    dgvCart.SelectedRows[0].Cells[10].Value = frm._textBox1.ToString();

    // second line - if you want to take any value to second form use this line
    // forth line - the place where you want to assign the value and the value returning from the second form.

    //In second form

    public string _textBox1
               get { return lblSpcCode.Text.Trim(); } *// the returning value*

    //write this code in gridview click event to get the cell value to textbox

    DataGridViewRow dr = dgvSpcCodes.SelectedRows[0];
    lblSpcCode.Text = dr.Cells[0].Value.ToString();

    //Once we click the row on datagridview getting the value of selected cell in to a textbox and returning the value to datagridview which is in form one without closing form one. like this you can pass the values between text boxes or datagridview to text box.

Log in to reply