Files
SDL/VERAG_PROG_ALLGEMEIN/Benutzerdefinierte Steuerelemente/MyListBox.vb

40 lines
1.0 KiB
VB.net

Imports System.ComponentModel
Public Class MyListBox
Inherits System.Windows.Forms.ListBox
Public Sub New()
End Sub
Sub fillWithMyListItem(l As List(Of MyListItem))
MyBase.Items.Clear()
For Each i In l : MyBase.Items.Add(i) : Next
End Sub
Sub fillWithSQL(sql As String, Optional showValueInText As Boolean = True, Optional conn As String = "SDL")
fillWithMyListItem((New SQL).loadCboBySqlWithListItem(sql, showValueInText, conn))
End Sub
Public Property _value As String
Get
Return getValueOfItem()
End Get
Set(v As String)
changeItem(v)
End Set
End Property
Sub changeItem(v)
For Each i In MyBase.Items
If DirectCast(i, MyListItem).Value = v Then
MyBase.SelectedItem = i : Exit Sub
End If
Next
End Sub
Function getValueOfItem() As String
Try : Return DirectCast(MyBase.SelectedItem, MyListItem).Value : Catch : End Try
Return ""
End Function
End Class