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

Asked

Viewed 729 times

0

I’m making a loyalty system, and I wanted to use two forms for customers, Form1 with the datagridview and a button register and the other form2 with the data fields to be filled in, that form2 would be triggered by pressing the sign-up button on Form1, hence when you saved the data in form2 they appear in the datagridview Form1. Can someone help me??

2 answers

1

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

Thus?

0

In Form1

1 - Create a Grid

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

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

In Form2

1 - Add Textedit with fields for Client registration

2 - Create a Save button in 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();
}

Browser other questions tagged

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