开发者

combobox inserting consecutive variables

开发者 https://www.devze.com 2022-12-31 03:21 出处:网络
I have a question about combobox.I use visual c# and I want to insert consecutive numbers (1 to 100) in 开发者_JS百科combobox.How can I do this?You need to use a for loop, like this:

I have a question about combobox.I use visual c# and I want to insert consecutive numbers (1 to 100) in 开发者_JS百科combobox.How can I do this?


You need to use a for loop, like this:

for (int i = 0; i < 100; i++) {
    comboBox.Items.Add(i + 1);
}

You can also use LINQ:

comboBox.DataSource = Enumerable.Range(1, 100).ToArray();
0

精彩评论

暂无评论...
验证码 换一张
取 消