|
-
Jul 29th, 2004, 02:09 AM
#1
Thread Starter
Frenzied Member
Performance Question about listboxes
hi all,
in Vb6 i was used to use an api called lockwindowupdate and pass it the handle of the control so it suspends the redrawing activity until i finish all my processing. This was very very useful in loading listboxes and comboboxes with 5000 Elements. It grants us a very fastr performance because it saved us repainting the control 5000 times.
in Vb.Net , i found 2 ways
for a list and a comboboxes you can use either :
1 - begineedit - EndEdit
2 - Suspend Layout - Resume Layout
i dont understand the difference between them and what i do really care for is which couple is faster so i will use it.
can any expertise person advise me this information
THX in Advance
-
Jul 31st, 2004, 09:12 AM
#2
Junior Member
From what the MSDN Library says, you would use BeginUpdate for this, and if possibly you would use AddRange over adding one at a time, then you wouldn't need to use BeginUpdate. I copied the text from the help here.
ListBox.BeginUpdate Method
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.
[Visual Basic]
Public Sub BeginUpdate()
Remarks
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.
Example
The following example uses the BeginUpdate and EndUpdate methods while adding five thousand items to a ListBox. This example assumes that a ListBox control, named listBox1, has been added to a Form and that this method is placed within the form and called from it.
[Visual Basic]
Public Sub AddToMyListBox()
' Stop the ListBox from drawing while items are added.
listBox1.BeginUpdate()
' Loop through and add five thousand new items.
Dim x As Integer
For x = 1 To 4999
listBox1.Items.Add("Item " & x.ToString())
Next x
' End the update process and force a repaint of the ListBox.
listBox1.EndUpdate()
End Sub
-------------------------------------------------------------------------------
Control.SuspendLayout Method
Temporarily suspends the layout logic for the control.
[Visual Basic]
Public Sub SuspendLayout()
Remarks
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 allow the changes to take effect.
Example
[Visual Basic, C#, C++] The following example adds two buttons to a form. The example transactions the addition of the buttons by using the SuspendLayout and ResumeLayout methods.
[Visual Basic]
Private Sub AddButtons()
' Suspend the form layout and add two buttons.
Me.SuspendLayout()
Dim buttonOK As New Button()
buttonOK.Location = New Point(10, 10)
buttonOK.Size = New Size(75, 25)
buttonOK.Text = "OK"
Dim buttonCancel As New Button()
buttonCancel.Location = New Point(90, 10)
buttonCancel.Size = New Size(75, 25)
buttonCancel.Text = "Cancel"
Me.Controls.AddRange(New Control() {buttonOK, buttonCancel})
Me.ResumeLayout()
End Sub
-
Jul 31st, 2004, 03:23 PM
#3
Thread Starter
Frenzied Member
well, then beginedit and endedit is preferred with list controls, while suspend layout works fine for GUI modifications.
That is what i call a professional talk, thx a lot fellow
BST RGDS
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|