Reputation: 11
I have a problem with progress bar. I have a button (SELECT * FROM Table
).
When I click it, I want to display data in datagridview. It's ok, works fine.
But now I need make a progress bar, while data is reading from DB.
By default progress bar visible should be as false. While reading - progress bar visible is true.
And when data is read from DB, progress bar visible should be false again.
I have a code, but it works incorrect (1. progress bar is buggy and etc.) Maybe you can offer me another variant?
private void button3_Click(object sender, EventArgs e)
{
timer1.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
progressBar1.Visible = true;
progressBar1.Minimum = 10;
progressBar1.Maximum = 100;
progressBar1.Increment(+10);
if (progressBar1.Value == 90)
{
groupBox3.Enabled = true;
connect con = new connect();
DataTable data = connnection.query("SELECT * FROM User WHERE surname LIKE '" + textBox1.Text + "%'");
dataGridView1.DataSource = tb;
}
if(progressBar1.Value == 100)
progressBar1.Visible = false;
}
Upvotes: 0
Views: 1897
Reputation: 6026
You need to rethink your logic.
When you make that SQL call think of it as code running outside your program, meaning you can only start it up and wait for it to finish, but you won't have access to the internals like how far it is progressing.
What you can do as an alternative is:
RunWorkerCompleted
happens, you can remove your Please Wait and bind up your data.Upvotes: 1