Catalin KokoTz

Catalin KokoTz

  • NA
  • 8
  • 627

NumericUpDown List and Button List . How to link them ?

Mar 14 2018 12:24 PM
Hello ,
 
I have a List of Buttons and a List of NumericUpDown.
  1. numUpDnList = new List();  
  2. btnList = new List();  
  3. for (int i = 0; i < maxv; i++)  
  4. {  
  5. Button btn = new Button();  
  6. btn.Location = new Point(121, 275 + i * 19);  
  7. this.Controls.Add(btn);  
  8. btnList.Add(btn);  
  9.   
  10. NumericUpDown numUpDn = new NumericUpDown();  
  11. numUpDn.Location = new System.Drawing.Point(120, 275 + i * 19);  
  12. // numUpDn.Size = new System.Drawing.Size(50, 20);  
  13. this.Controls.Add(numUpDn);  
  14. numUpDnList.Add(numUpDn);  
  15. }  
I want to: btnList[i].Click += (se, ev) => { numUpDnList[i].UpButton(); }
 
But it doesn't work :
 
" System.ArgumentOutOfRangeException: 'Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index' "

Answers (3)