Progress bar c# (windows form) using mysql data

Asked

Viewed 119 times

0

I currently have this code in one of the formats of a developing application and would like to create a progress bar that by clicking the View button (which takes a while to fill the datagrid) would show the progress of the data.

namespace Odin
{
    public partial class frmBuscaPorNome : Form
    {
        public frmBuscaPorNome()
        {
            InitializeComponent();
        }

        Conexao bd = new Conexao();

        private void CarregarGrid()
        {
            string sql = "SELECT * FROM ebt_iw ORDER BY id;";
            dtgBusca.DataSource = bd.ExecutarConsultas(sql);
        }

        private void btnBusca_Click(object sender, EventArgs e)
        {
            string Busca = txtBusca.Text;
            string bsc = "SELECT * FROM ebt_iw WHERE nome LIKE '" + Busca + "%' ;";
            dtgBusca.DataSource = bd.ExecutarConsultas(bsc);

        }

        private void btnVer_Click(object sender, EventArgs e)
        {
            CarregarGrid();
        }

        private void btnSair_Click(object sender, EventArgs e)
        {
            Close();
        }
    }

This is the connection class:

 class Conexao
    {
        MySqlConnection conexao;

        public void Conectar()
        {
            string string_conexao = "Persist Security Info = false;server = localhost;database = ebtiw;uid = root;pwd = ;SslMode=none;";
            conexao = new MySqlConnection(string_conexao);
            conexao.Open();
        }

        public void ExecutarComandos(string sql)
        {
            Conectar();
            MySqlCommand comando = new MySqlCommand(sql, conexao);
            comando.ExecuteNonQuery();
            conexao.Close();
        }

        public DataTable ExecutarConsultas(string query)
        {
            Conectar();

            DataTable dt = new DataTable();
            MySqlDataAdapter dados = new MySqlDataAdapter(query, conexao);
            dados.Fill(dt);
            conexao.Close();

            return dt; //dt armazena os resultado obtido de execuçao do SELECT ( da string query)
        }

    }
}
  • Defining directly the DataSource cannot have the behavior you want. If you add line by line, then yes, you could, but lost performance...

  • Voce indicates another way to do this? like display a text box written 'loading' until the table loads ?

  • No, add row by row to the grid within a cycle and at the same time increase the value of the ProgressBar.

  • has some event or property that I can know when the table fully loads?

  • Yes, by the grill event DataBindingComplete (if it is a DataGridView).

  • Thank you very much friend, you helped me so much

Show 1 more comment
No answers

Browser other questions tagged

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