0
Good afternoon. I need help, I have a datagridwier and in it I have a column where I type in a product code. Now I need that when the user enters the code of a product in the cell of the code column to enter it fill the product field and also the batch combobox with data from a select I bring from the database. How can I do that?
follows below the screen of my datagridwier
Sqlconnection conex = new Sqlconnection(Properties.settings.Default.Dadosadvconnectionstring); Sqlcommand command = null; public frmSoliciatcaAmostraPic() { InitializeComponent(); }
private void lbl_email_Click(object sender, EventArgs e)
{
}
private void btn_ok_Click(object sender, EventArgs e)
{
if (txt_codcli.Text != "")
{
SqlCommand comando = new SqlCommand(@"SELECT
SA.A1_NREDUZ AS CLIENTE,
+'(' + SA.A1_DDD + ')' + ' ' + SA.A1_TEL AS TELEFONE,
SA.A1_CEP AS CEP,
SA.A1_END AS ENDERECO,
SA.A1_BAIRRO AS BAIRRO,
SA.A1_MUN AS CIDADE,
SA.A1_EST AS ESTADO,
CONVERT(VARCHAR(10), CAST(SA.A1_DTNASC AS DATE), 103) AS DATA
FROM SA1010 AS SA
WHERE SA.A1_COD = '" + txt_codcli.Text + "'", conex);
comando.CommandType = CommandType.Text;
conex.Open();
SqlDataReader dr = comando.ExecuteReader();
while (dr.Read())
{
txt_cliente.Text = dr["CLIENTE"].ToString();
txt_telefone.Text = dr["TELEFONE"].ToString();
txt_cep.Text = dr["CEP"].ToString();
txt_endereco.Text = dr["ENDERECO"].ToString();
txt_bairro.Text = dr["BAIRRO"].ToString();
txt_cidade.Text = dr["CIDADE"].ToString();
txt_uf.Text = dr["ESTADO"].ToString();
txt_dtcadastro.Text = dr["DATA"].ToString();
}
conex.Close();
}
else
{
MessageBox.Show("Código do cliente invalido, por favor digitar um código de clinete válido");
return;
}
}
}
}
Sorry, I just put the code in the question. So what you want is accurate and when I type the code of a product on the grid it already fills the columns automatically.I was thinking of using Keydown in the cell content, it is possible?
– Junior Guerreiro
Let me see if I understand, you want in the Datagrid code column the user type a code and when I leave the cell run a query and bring the results?
– Renan Silveira
That’s right, when you leave the cell run a select where or bring the product name and the lot and fill in the datagrid
– Junior Guerreiro
Renan solved the problem by changing the type of insertion on the grid, I created the fields that I need to be filled in on the grid then created an Insert button that enters the data on the grid. But thank you very much for your attention.
– Junior Guerreiro