Last active
September 2, 2015 17:14
-
-
Save wolf99/d31cfc8360f7681eae4f to your computer and use it in GitHub Desktop.
Extension to fill a VB.NET ComboBox control from a collection or list of strings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' Requires `Imports System.Runtime.CompilerServices` | |
Module Extensions | |
<Extension()> | |
Public Function Fill(Of T)(cb As Control, cc As ICollection(Of T)) As Integer | |
Dim cbc As ComboBox = CType(cb, ComboBox) | |
Dim n As Integer = 0 | |
If cc.Count = 0 Then | |
Return False | |
End If | |
For Each cn In cc | |
If cbc.Items.Add(cn.ToString) = 1 Then | |
n = n = 1 | |
End If | |
Next | |
Return n | |
End Function | |
<Extension()> | |
Public Function Fill(cb As Control, first As Integer, last As Integer, stepsize As Integer) As Integer | |
Dim cbc As ComboBox = CType(cb, ComboBox) | |
Dim n As Integer = 0 | |
For i As Integer = first To last Step stepsize | |
If cbc.Items.Add(i.ToString) = 1 Then | |
n = n + 1 | |
End If | |
Next | |
Return n | |
End Function | |
<Extension()> | |
Public Function Fill(cb As Control, first As Integer, last As Integer) As Integer | |
Dim s As Integer = 1 | |
If first > last Then | |
s = -1 | |
End If | |
Return cb.Fill(first, last, s) | |
End Function | |
<Extension()> | |
Function Fill(cb As Control, last As Integer) As Integer | |
Dim s As Integer = 1 | |
If 0 > last Then | |
s = -1 | |
End If | |
Return cb.Fill(0, last, s) | |
End Function | |
End Module |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment