1
I am trying to execute a method within a textbox, only if the user gives enter. Check that I have to use Keypress, but I’m not able to apply. I want when the user puts the product code inside the textbox and enter, he can see the product. Code Below :
private void textBox1_TextChanged(object sender, EventArgs e)
{
try
{
int Codigo = Convert.ToInt32(txtCodigo.Text);
ProdutoDAL d = new ProdutoDAL();
Produto p = d.ConsultarProduto(Codigo);
if (p != null)
{
txtDescricao.Text = Convert.ToString(p.Estoque_descricao);
txtReferencia.Text = Convert.ToString(p.Estoque_referencia);
txtComplemento.Text = Convert.ToString(p.Estoque_descricao2);
txtCodBarras.Text = Convert.ToString(p.Estoque_codbarras);
txtCustoMedio.Text = Convert.ToString(p.Estoque_customedio);
txtValorAVista.Text = Convert.ToString(p.Estoque_avista);
txtValorTabela.Text = Convert.ToString(p.Estoque_tabela);
txtValorPromocao.Text = Convert.ToString(p.Estoque_promocao);
txtValorComDesconto.Text = Convert.ToString(p.Estoque_desconto);
txtLinha.Text = Convert.ToString(p.Estoque_linha);
txtSetor.Text = Convert.ToString(p.Estoque_setor);
txtfigura.Text = Convert.ToString(p.Estoque_figura);
txtMarca.Text = Convert.ToString(p.Estoque_marca);
}
else
{
MessageBox.Show("PRODUTO NAO CADASTRADO");
}
}
catch (Exception ex)
{
throw new Exception("ERRO AO CONSULTAR PRODUTO" + ex.Message);
}
}
C# is not my thing but knowing that it is used for the web is worth asking: is this textbox HTML? If it is you have to capture the keypress with Javascript (jQuery using something like keyup or change). If it is web warns that I give a help on the JS side. ;)
– Fernando Cordeiro