Click here to Skip to main content
15,913,685 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I need some help with progressbar in C#, I want a Progresbar that when I click on a button the progresbar to sort then event should happen.

e.x
I have this list in a listbox1:

CCCC
BBBB
AAAA
....
....

So when I click button, before the data sort progresbar shuld start...and after progresbar is end.... then a want to see the data sorted.

hope to be very clearly

??!
Posted
Comments
Sandeep Mewara 3-May-12 10:40am    
What effort have you made till now? Where are stuck? Right now, it is just a problem statement. Where exactly you are looking help for?
h7h7h7 3-May-12 11:54am    
hi Sandeep, how can i do that code: when I click in a buttton "sort", the data should not be sorted until the progresbar end. after e progresbar ende then I want to show data in a listbox1. that'is something same when you delete any file and a progesbar start during they are deleting

1 solution

Add timer control
Set Interval for timer to 1000
Set progressbar step to 25


In tick event handle value updation of progress bar as below
Refer the following code


C#
public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        int tks;

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (tks != 4)
            {
                tks++;
                progressBar1.PerformStep();
            }
            else
            {
                timer1.Enabled = false;
                //sort listview listview1.sorted=true;
                listBox1.Sorted = true;
            }

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            tks = 0;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            timer1.Enabled = true;
        }
    }
}





Best of luck.........

Hope this helps...........
 
Share this answer
 
v3
Comments
h7h7h7 3-May-12 11:51am    
in fact it works, but data are sorted first then progresbar start :(....

I mean the progresbar must start first then data to be sorted
Mantu Singh 4-May-12 3:59am    
Sry now I hv updated the answer
After adding progress bar ensure that enabled is set to false
best of luck.....
h7h7h7 4-May-12 5:18am    
hmmm I have no doubt that this code isn't working, but I think I don't know to implement it, can you halp me where to set those code in wich part:
timer1.interval=1000;
progressbar.step=25;

then I din't understand that: In tick event handle value

the other code I have implement all..
Mantu Singh 4-May-12 10:33am    
In properties window.........

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900