Automatic line filling in datagridwier

Asked

Viewed 69 times

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 inserir a descrição da imagem aqui

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;
        }
    }
}

}

1 answer

0


Good afternoon, I think if you put part of the code would help a lot, but I have a similar project, but I feed the Grid with an Array that I receive from a Webservices, I will put the code below.

         // o Registro contem dada dado concatenado e separado por ";"   
        for (int i = 0; i < registros; i++)
        {
            dataGridPermissoes.Rows.Add();

            var metadadoscort = ListRegistros[i + 1];
            var Listametadados = metadadoscort.Split(';');

            var permissao = "";
            if (Listametadados[10].Equals("M"))
            {
                permissao = "Modificar";
            }
            else if (Listametadados[10].Equals("R"))
            {
                permissao = "Remover";
            }
            else
            {
                permissao = "Leitura";
            }
             // Em vez de vc colocar "Listametadados[]" vc vai colocar o campos da tabela.
            dataGridPermissoes.Rows[i].Cells[0].Value = Listametadados[2];
            dataGridPermissoes.Rows[i].Cells[1].Value = Listametadados[4];
            dataGridPermissoes.Rows[i].Cells[2].Value = Listametadados[6];
            dataGridPermissoes.Rows[i].Cells[3].Value = Listametadados[8];
            dataGridPermissoes.Rows[i].Cells[4].Value = permissao;
        }
  • 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?

  • 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?

  • 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

  • 1

    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.

Browser other questions tagged

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