kesiana

how can I add an item to a listbox when I am running a program loop

I have a listbox in window form. I will like to add items to the listbox and display the items while running a program loop. How can I accomplish this

for example:

ListBox list;

for(int i = 1; i < 50; i++)

{

list.Items.Add(i.ToString());

}

PROBLEM

The items in the ListBox will not display until the loopping has completed. This is not good enough. I want to be displaying information in the ListBox while the loop is still running.

Please help me.



Re: Windows Forms General How to add item to a listbox in a program loop

Mahesh Chand

I am not sure but did you try calling Refresh or DataBind methods



Re: Windows Forms General How to add item to a listbox in a program loop

nobugz

Odd request, that loop will take less than a microsecond. Nevertheless, you'd call the ListBox' Update() method to let it paint itself.





Re: Windows Forms General How to add item to a listbox in a program loop

Timo S

If you have much more items and when you update that listbox all the time, it may blink like an epileptic light. Then I recommend you to use double buffering:


Code Snippet

this.DoubleBuffered = true;


I'm not sure if it's written in that way, but something like that.