Good morning, everyone.
Next, I have a form (query) that contains the DataGridView. And the registration form in another form.
I would like to understand, how can I double-click a row in the DataGridView to send all the data in the row to this registration form (so I can make the crud to change).
Image to illustrate:
Datagridclass
classdatagride{bancoconexao=newbanco();//AtributosprivatestringnomeTabela;privateDataGridViewnomeDataGride;//Construtorpublicdatagride(stringpnt,DataGridViewpndg){nomeTabela=pnt;nomeDataGride=pndg;}publicdatagride(DataGridViewpndg){nomeDataGride=pndg;}//MétodopublicDataGridViewcarregarGride(stringsql="")
{
DataSet ds = new DataSet();
DataTable dt = new DataTable(); //Nova tabela
ds.Tables.Add(dt);
NpgsqlDataAdapter da = new NpgsqlDataAdapter();
if (sql == "")
{
sql = "select * from " + nomeTabela;
}
da = new NpgsqlDataAdapter(sql, conexao.conecta());
da.Fill(dt);
nomeDataGride.DataSource = dt.DefaultView;
conexao.desconecta();
return nomeDataGride;
}
** Builder **
public cliente(cliente c, string pn, string pe, int pt, string pem, string ps, int pcod)
{
nome = pn;
endereco = pe;
telefone = pt;
email = pem;
sexo = ps;
cod = pcod;
}
Instance in form
private void btnAtualizar_Click(object sender, EventArgs e)
{
if (txtCodC.Text == "")
{
MessageBox.Show("Digite o código do cliente");
txtCodC.Focus();
}
else
{
try
{
cliente cli = new cliente(txtNomeCliente.Text, txtEnderecoCliente.Text, Convert.ToInt32(txtTelefoneCliente.Text), txtEmailCliente.Text, cmbSexoCliente.Text, Convert.ToInt32(txtCodC.Text));
cli.AlterarCliente();
MessageBox.Show("Alterado com sucesso!");
}
catch (Exception ex) // Caso de erro, irá mostrar a mensagem de erro!
{
MessageBox.Show(ex.ToString()); // mensagem de erro
}
}
}