Data does not appear in Datagridview C#

Asked

Viewed 23 times

-2

I have Datagridview in two forms of my project, but only appear the data in one, and the other is not appearing, I’ve reviewed everything but it seems all right for me.

Form Load Code

    private void CriarOrc_Load(object sender, EventArgs e)
    {

        dgv_produtos1.DataSource = Banco.ObterProdutosGrid();
        
        dgv_produtos1.Columns[0].Width = 70;
        dgv_produtos1.Columns[1].Width = 250;
        dgv_produtos1.Columns[2].Width = 70;
        dgv_produtos1.Columns[3].Width = 80;
        dgv_produtos1.Columns[4].Width = 70;


    }

Code of class Bank

   public static DataTable ObterProdutosGrid()
        {
            SQLiteDataAdapter da = null;
            DataTable dt = new DataTable();
            try
            {
                var vcon = ConexaoBanco();
                var cmd = vcon.CreateCommand();
                cmd.CommandText = "SELECT idprod as 'ID Produto', nome as 'Nome', medida as 'Medida', qtd as 'Quantidade', valor as 'Valor' FROM tb_produto";
                da = new SQLiteDataAdapter(cmd.CommandText, vcon);
                da.Fill(dt);
                vcon.Close();
                return dt;

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

1 answer

0


I GOT THROUGH A BUTTON. I PUT THE PREVIEW BUTTON AND I ENCODED THE BUTTON NORMALLY AND IT WORKED. I STILL DON’T KNOW WHY IT DIDN’T SHOW UP ON LOAD, BUT THAT’S THE SOLUTION I FOUND.

 private void btn_visualizar_Click(object sender, EventArgs e)
    {

        dgv_produtos1.DataSource = Banco.ObterProdutosGrid();
        
        dgv_produtos1.Columns[0].Width = 70;
        dgv_produtos1.Columns[1].Width = 250;
        dgv_produtos1.Columns[2].Width = 70;
        dgv_produtos1.Columns[3].Width = 80;
        dgv_produtos1.Columns[4].Width = 70;


    }

Browser other questions tagged

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