简体   繁体   中英

vb.net add value in combobox

I'm currently adding values into a combobox using a For statement but this cannot be the best solution?

Combobox needs to be filled with values based on 1 variable integer.

Dim oOptions As Integer = 5

This should fill my combobox as:

1
2
3
4
5

Now i'm using but is there another way to do this?

For i = 1 to oOptions

Here is one line, code-efficient way, not execution efficient because Linq is syntax sugar

cboBox.DataSource = Enumerable.Range(1, 10).Select(Function(x) x).ToArray()

Now, replace 1 And 10 with variables and this will be very dynamic one-liner

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM