Imports System.ComponentModel Imports DevExpress.XtraEditors Imports DevExpress.XtraEditors.Controls Public Class LookupControl Public Property MultiSelect As Boolean Public Property AllowAddNewValues As Boolean Public Property PreventDuplicates As Boolean Public Property DataSource As DataTable Public Property SelectedValues As New List(Of String) Private _lookupControlMulti As GridLookUpEdit Private _lookupControlSingle As ButtonEdit Private Const TAG_BUTTON_LOOKUP_FORM = "openLookupForm" Private Const TEXT_NO_RECORDS = "Keine Datensätze ausgewählt" Private Const TEXT_N_RECORDS = "{0} Datensätze ausgewählt" Private Function GetLookupForm() As frmLookupGrid Dim oForm As New frmLookupGrid() With { .MultiSelect = MultiSelect, .AddNewValues = AllowAddNewValues, .PreventDuplicates = PreventDuplicates, .DataSource = DataSource, .SelectedValues = SelectedValues, .StartPosition = Windows.Forms.FormStartPosition.Manual, .Location = PointToScreen(New System.Drawing.Point(Width, 0)) } Return oForm End Function Private Sub Grid_Load(sender As Object, e As EventArgs) Handles Me.Load If MultiSelect = False Then _lookupControlSingle = New ButtonEdit With { .Dock = Windows.Forms.DockStyle.Fill } AddHandler _lookupControlSingle.ButtonClick, AddressOf lookupControlSingle_ButtonClick Controls.Add(_lookupControlSingle) Else _lookupControlMulti = New GridLookUpEdit With { .Dock = Windows.Forms.DockStyle.Fill } With _lookupControlMulti.Properties .View.OptionsBehavior.ReadOnly = True .View.OptionsBehavior.Editable = False .View.OptionsView.ShowColumnHeaders = False .PopupFormSize = New System.Drawing.Size(.PopupFormSize.Width, 100) End With _lookupControlMulti.Properties.Buttons.Add(New EditorButton() With { .Kind = ButtonPredefines.Ellipsis, .Tag = TAG_BUTTON_LOOKUP_FORM }) AddHandler _lookupControlMulti.ButtonClick, AddressOf lookupControlMulti_ButtonClick AddHandler _lookupControlMulti.EditValueChanging, AddressOf lookupControlMulti_EditValueChanging Controls.Add(_lookupControlMulti) End If End Sub Private Sub lookupControlMulti_EditValueChanging(sender As Object, e As ChangingEventArgs) e.Cancel = True End Sub Private Sub lookupControlMulti_ButtonClick(sender As Object, e As ButtonPressedEventArgs) If e.Button.Tag <> TAG_BUTTON_LOOKUP_FORM Then Exit Sub End If Dim oForm As frmLookupGrid = GetLookupForm() Dim oResult = oForm.ShowDialog() If oResult = Windows.Forms.DialogResult.OK Then Dim oValues = oForm.SelectedValues _lookupControlMulti.Properties.DataSource = oValues _lookupControlMulti.Properties.NullText = IIf(oValues.Count = 0, TEXT_NO_RECORDS, String.Format(TEXT_N_RECORDS, oValues.Count)) SelectedValues = oValues End If oForm.Dispose() End Sub Private Sub lookupControlSingle_ButtonClick(sender As Object, e As ButtonPressedEventArgs) Dim oForm As frmLookupGrid = GetLookupForm() Dim oResult = oForm.ShowDialog() If oResult = Windows.Forms.DialogResult.OK Then Dim oValues = oForm.SelectedValues _lookupControlSingle.Text = oValues.FirstOrDefault() SelectedValues = oValues End If oForm.Dispose() End Sub End Class