Pass data from a Datagridview to Textboxes in C#

Asked

Viewed 93 times

0

Hi, I’m having a problem and I’ve even asked a similar question before, but now I’m being more specific.

I have two Forms, one form has a Datagridview connected to a Database and the other form will serve as editing for the data of the records shown in that Datagridview.

For this to happen, the user will select a line with a Datagridview record and click the Edit button, which will open the other form.

I don’t know how to do the following part: I need to pass the data of the records that are in the dataGridView in the main form to the textBoxes of the editing form, so that it is possible to change this data.

If anyone can help, I’d be grateful I’m using Windows Form.

1 answer

0

    //ESTE É O FORM DA EDIÇÃO 
    public partial class frm_edit : Form
     {
         public string Nome;
         public int Idade;
     }

       // este é o evento load do form da edição
    private void frm_edit_Load(object sender, EventArgs e)
    {
         txtNome.Text=Nome;
         txtIdade.Text=Idade+"";
    }


    // AQUI NO FORM ONDE ESTA A DataGridView1  NO CLICK DO BOTÃO 
     {

       frm_edit  FE=new frm_edit();

      FE.Nome= Convert.ToString(DataGridView1[0,DataGridView.CurrentRow.Index].Value);
      FE.Idade= Convert.ToInt32(DataGridView1[1,    DataGridView.CurrentRow.Index].Value);

      FE.Show();

the numbers 0 and 1 are the columns, in this case:

0-Nome 1-Age

}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.