can anyone tell me what is the difference between suspendlayout and begin update??
Dear all, read the thread title. i am looking to optimize my performance when loading long lists, i am confused which is better beginupdate or suspend layout and the more important is why ?
i need to know the technical difference if anybody knows !!!
thank you in advance, all of you
bst rgds
Re: can anyone tell me what is the difference between suspendlayout and begin update??
BeginUpdate is when you don't want the control to repaint after each item is added, whereas SuspendLayout does exactly that, suspends the layout events for the control.
Straight from the MSDN library:
Quote:
Originally Posted by MSDN Library Re:Control.SuspendLayout
The layout logic of the control is suspended until the ResumeLayout method is called.
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.
Quote:
Originally Posted by MSDN Library Re:ListView.BeginUpdate
The preferred way to add multiple items to a ListView is to use the AddRange method of the ListView.ListViewItemCollection (accessed through the Items property of the ListView). 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 ListView.ListViewItemCollection class, you can use the BeginUpdate method to prevent the control from repainting the ListView each time an item is added. Once you have completed the task of adding items to the control, call the EndUpdate method to enable the ListView to repaint. This way of adding items can prevent flickered drawing of the ListView when a large number of items are being added to the control.
You can substitute ListView for a number of different controls to achieve the same result, some examples include the ListBox, ComboBox, TreeView etc.
Re: can anyone tell me what is the difference between suspendlayout and begin update??
i guess the answer is , they are similar to each other except that beginupdate only affects repaints events coming by adding items while suspend layout is more powerfull as it freezes the control totally (adding items and also changing appearance).
i think i will stick to suspend and resume layout
thank you for your information, i would be more than glad to hear other opinions if anyone have any??
thank you again for your time
bst rgds
Re: can anyone tell me what is the difference between suspendlayout and begin update??
No, that's not what it means at all, did you read it? SuspendLayout does not suspend the paint ones, that's BeginUpdate. If you start trying to take shortcuts instead of using the proper methods, then your app will start to become harder and harder to maintain, stick with the proper methods, then you shouldn't have much trouble.