Updating listbox without refreshing window for each element added

  • Thread starter Thread starter Zytan
  • Start date Start date
Z

Zytan

In win32 there was a way to 'turn off' a listbox from updating until
you were done adding elements. Is there a way to do this in .NET?

Zytan
 
In win32 there was a way to 'turn off' a listbox from updating until
you were done adding elements. Is there a way to do this in .NET?

Zytan

Have you looked into the .SuspendLayout() and .ResumeLayout() methods?
 
Have you looked into the .SuspendLayout() and .ResumeLayout() methods?

No. The docs say:

"The SuspendLayout and ResumeLayout methods are used in tandem to
suppress multiple Layout events while you adjust multiple attributes
of the control. For example, you would typically call the
SuspendLayout method, then set the Size, Location, Anchor, or Dock
properties of the control, and then call the ResumeLayout method to
enable the changes to take effect."

So, it looks like this is close, but not quite what I want. Thanks.

Zytan
 
I was thinking .BeginUpdate() and .EndUpdate()

Yup, this is it!

"Maintains performance while items are added to the ListBox one at a
time by preventing the control from drawing until the EndUpdate method
is called."

But note:

"The preferred way to add multiple items to the ListBox is to use the
AddRange method of the ListBox.ObjectCollection class (through the
Items property of the ListBox). This enables you to add an array of
items to the list in a single operation. However, if you want to add
items one at a time using the Add method of the
ListBox.ObjectCollection class, you can use the BeginUpdate method to
prevent the control from repainting the ListBox each time an item is
added to the list. Once you have completed the task of adding items to
the list, call the EndUpdate method to enable the ListBox to repaint.
This way of adding items can prevent flickered drawing of the ListBox
when a large number of items are being added to the list."

Thanks!

Zytan
 
I was thinking .BeginUpdate() and .EndUpdate()

I don't suppose there's such a thing for a RichTextBox?

Zytan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top