2
Hello I’m trying to do something that seems simple but I’m not getting, I want to click on a button add the data of a grid go to another form that is already open. the problem is that I am only able to click on a new form that is not what I want follows code for help:
Add Form1 button event
private void btnAdicionar_Click(object sender, EventArgs e)
{
frmPedidos frmped = new frmPedidos(CODIGO, NOME, TELEFONE, ENDERECO);
CODIGO = int.Parse(dgvConsultaCliente.CurrentRow.Cells[0].Value.ToString());
NOME = dgvConsultaCliente.CurrentRow.Cells[1].Value.ToString();
TELEFONE = dgvConsultaCliente.CurrentRow.Cells[2].Value.ToString();
ENDERECO = dgvConsultaCliente.CurrentRow.Cells[3].Value.ToString();
frmped.Show();// aqui que ele carrega outro form tanto faz se usar ShowDialog ou Show mesmo
}
Form 2
public frmPedidos(int codigo, string nome, string telefone, string endereco)
{
InitializeComponent();
txtCodCliente.Text = codigo.ToString();
txtNomeCliente.Text = nome;
txtTelefoneCliente.Text = telefone;
txtEndCliente.Text = endereco;
}
I want to fill in the form already opened and not in a new form because I will put other tables that will do the same process if I do this in all I will lose the information.
From now on I thank you all.
Hello Fernando already thank you for the help so I did what you are suggesting more I’m having problems when I put the 'var _frmped = new frmPedidos();' in scope nor can I open my application form already error when I put in the button event nothing happens, I’m still studying what you’ve done to try to solve here also more unsuccessfully so far. Got any more tips?
– Jameson
@Jameson, I made a small adjustment to the code. I have tested and worked here.
– Fernando
So this way it works in _frmped. Show(); only that it opens another form and what is already open is not filled I think you have to encapsulate the textbox but I don’t know much about how to proceed.If that’s the case
– Jameson
With the code you posted, there is no way to know how the opening of
frmPedidos
. If you’re opening upfrmPedidos
before opening Form1, you will have to pass it as parameter to Form1– Fernando
I changed the code to show how you can pass the form opened as a parameter to Form1
– Fernando
It worked out with the way you did, the only thing you couldn’t do was to take the data of the Client who had already created the get and set methods in a separate class and to pull it out is right. Very Thanks.
– Jameson