for (int i = 0; i < 5; i++)
{
dataGridView1.Columns.Add("col", "col");
Thread.Sleep(1000);
}
When I run this code all the columns show up at one time after 5s not one by one every 1 second. Please help me, I don't want to use timers.
You don't give the form a chance to redraw itself.
Call Invalidate
and then Update
before going to sleep.
This is extremly extremly nasty code, and you Should use timers.
However, if you insist on doing it this way, try to throw in a Application.DoEvents()
(shudder) after the Thread.Sleep(100);
line.
By the way, why do you not want to use timers? They are very easy to set up and will make this code much cleaner than it will end up this way.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.