How to fill a datagrid in a form with fields in another form C #?

0

I'm doing a loyalty system, and wanted to use two forms for clients , form1 with datagridview and a button to sign up and the other form2 with the data fields to be filled , this form2 would be triggered by pressing the form1 button, when saving the data in form2 they appear in the datagridview of form1 . Can anyone help me ??

    
asked by anonymous 17.09.2014 / 22:18

2 answers

1
   DataGridViewButtonCell b = new DataGridViewButtonCell();
        int rowIndex = MainTable.Rows.Add(b);
        MainTable.Rows[rowIndex].Cells[0].Value = "name";

Like this?

    
18.09.2014 / 18:25
0

No Form1

1 - Create a Grid

2 - Create a Join button on Form1 and add the Click event:

private void Cadastrar_Click(object sender, EventArgs e)
{
     new Frm2().ShowDialog();
     Grid.DataSource = ConsultarClienteGravadosBancoDados();
     Grid.RefreshDataSource();
}

No Form2

1 - Add the TextEdit with the fields for the Customer registry

2 - Create a Save button on Form2 and add the Click event:

private void Salvar_Click(object sender, EventArgs e)
{
     cliente.Codigo = textEdit1.Text;
     cliente.Nome = textEdit2.Text;
     InserirClienteBancoDados(cliente);

     this.Close();
}
    
03.03.2017 / 20:04