468,107 Members | 1,302 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,107 developers. It's quick & easy.

Updating listbox without refreshing window for each element added

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

May 7 '07 #1
6 3716
On May 7, 4:38 pm, Zytan <zytanlith...@gmail.comwrote:
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?

May 7 '07 #2
Have you looked into the .SuspendLayout() and .ResumeLayout() methods?
I was thinking .BeginUpdate() and .EndUpdate()

May 8 '07 #3
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

May 8 '07 #4
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

May 8 '07 #5
On May 7, 5:14 pm, not_a_commie <notacom...@gmail.comwrote:
Have you looked into the .SuspendLayout() and .ResumeLayout() methods?

I was thinking .BeginUpdate() and .EndUpdate()
Oh, yes. Silly me. :-)

May 8 '07 #6
I was thinking .BeginUpdate() and .EndUpdate()

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

Zytan

May 8 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by gdbjohnson-AT-yahoo-dot-ca-nospamplz | last post: by
1 post views Thread by Spock | last post: by
1 post views Thread by erin.sebastian | last post: by
4 posts views Thread by P K | last post: by
5 posts views Thread by JJ | last post: by
3 posts views Thread by Sweetiecakes | last post: by
1 post views Thread by Solo | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.