Reputation: 7501
I have this code that add items to a context menu's sub-menu:
CTX_VALUE.Enabled = True
CTX_VALUE.Visible = True
CTX_VALUE.Text = "List Values"
For k As Integer = 0 To CELL.VALUE_LIST.Count - 1
CTX_VALUE.DropDownItems.Add(CELL.VALUE_LIST(k))
Next k
Where CTX_VALUE
is a ToolStripMenuItem
and CELL.VALUE_LIST
is an ArrayList
(yeah, old code!) of ToolStripMenuItems
When it comes to add about 150 items, it becomes really slow, about 2.5 seconds.
Visibility before adding doesn't matter, i tried moving it after.
BTW, note that the context menu is not on screen when adding items!
I also tried suspending layout of CTX_VALUE
before adding. No luck.
Upvotes: 1
Views: 803
Reputation: 298
Before the add items loop I used both
ts_filter.DropDown.SuspendDrawing (see addendum note below)
and
ts_filter.DropDown.SuspendLayout
After the loop I used the corresponding resume methods. This made a huge difference to my program moving it from unworkable to instant.
Addendum:- The resumedrawing (alone) was preventing my custom textbox (inherited from toolstriptextboxfrom) from showing. I found the suspendlayout and resumelayout to be ok alone though and it kept the speed up.
Upvotes: 1
Reputation: 2072
you should add these using CTX_VALUE.DropDownItems.AddRange()
method
Upvotes: 3