vb.netwinformstoolstripdropdown

WinForms context menu really slow adding 150 Toolstrip Menu Items


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.


Solution

  • you should add these using CTX_VALUE.DropDownItems.AddRange() method