How to add List items in contextMenuStrip with any loop? Is there any way like DataBinding etc?
Asked
Active
Viewed 188 times
-2
-
Title says without loop, question says with loop. Either way, why? You shouldn't have that many menu items that it has to be managed with DataBinding. I'm sure WPF can do that though. – LarsTech Aug 20 '15 at 14:45
-
My application is in WinForm, and Data to be processed is very huge. Feeling risk to use Loop. – Syed Faizan Ali Aug 20 '15 at 14:47
-
So you want to have the user handle how many menu items? Don't understand the "risk" part. – LarsTech Aug 20 '15 at 14:55
-
I simply want to Bind my List
with contextMenuStrip to populate. I have thousands of iterations, and task can not be aborted during execution. That's why I'm trying to avoid loop here. – Syed Faizan Ali Aug 20 '15 at 15:00 -
I don't know what you are doing, but it makes no sense whatever it is. You do know that even with data binding, there is still a loop involved? DataBinding just takes care of the looping for you. – LarsTech Aug 20 '15 at 15:27
1 Answers
0
I did it by using this Recusive method:
public ContextMenuStrip ItemInsertion(ContextMenuStrip contextMenuStrip, List Items)
{
int counter = contextMenuStrip.Items.Count;
if (contextMenuStrip.Items.Count != (Items.Count))
{
contextMenuStrip1.Items.Add(Items.ElementAt(counter));
ItemInsertion(contextMenuStrip, Items);
}
return contextMenuStrip;
}

Syed Faizan Ali
- 9
- 4
-
As Recursion is faster than loop when Data to be processed is very huge. Loop is fast for small data and recursion is a little bit slower but when the data is huge, Loop cannot beat Recursion. – Syed Faizan Ali Sep 15 '16 at 16:34