Click here to Skip to main content
15,889,900 members
Please Sign up or sign in to vote.
1.20/5 (3 votes)
how to get 1 to 100 numbers in combo box
Posted
Comments
Naz_Firdouse 18-Apr-14 6:29am    
what have you tried so far?

Little bit of a PITA - because the Addrange method only accepts an array of objects, but...
Try:
C#
myComboBox.Items.AddRange(Enumerable.Range(1, 100).Select(i => (object) i).ToArray());
 
Share this answer
 
Comments
hilbert hussen 18-Apr-14 7:15am    
not getting
OriginalGriff 18-Apr-14 7:18am    
"not getting" is not a helpful error report: perhaps if you describe what is and isn't happening in rather more detail, it might help?
Mark Spears 28-Apr-21 12:45pm    
This is a great short quick solution. Note you must have "using System.Linq;" in your using list at the top to use the shortened form above.
Question is not clear, did you mean?

C#
var list = comboBox1.Items.Cast<int>().Select(item => item).ToList().GetRange(0,100);
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900