First Pass of new LookupControl

This commit is contained in:
Jonathan Jenne
2019-03-22 13:44:20 +01:00
parent 07c44d69c4
commit 21ee4416ef
5 changed files with 65 additions and 264 deletions

View File

@@ -7,6 +7,9 @@ Imports DevExpress.XtraEditors.Repository
Imports DevExpress.XtraEditors.ViewInfo
Imports DevExpress.XtraEditors.Popup
Imports DevExpress.Accessibility
Imports DevExpress.XtraEditors.Controls
<UserRepositoryItem("RegisterLookupControl2")>
Public Class RepositoryItemLookupControl2
@@ -51,14 +54,76 @@ End Class
Public Class LookupControl2
Inherits GridLookUpEdit
Public Property MultiSelect As Boolean
Public Property AllowAddNewValues As Boolean
Public Property PreventDuplicates As Boolean
Public Property DataSource As DataTable
Public Property SelectedValues As List(Of String)
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"
Shared Sub New()
RepositoryItemLookupControl2.RegisterLookupControl2()
End Sub
Public Sub New()
Properties.Buttons.Add(New EditorButton() With {
.Kind = ButtonPredefines.Ellipsis,
.Tag = TAG_BUTTON_LOOKUP_FORM
})
AddHandler ButtonClick, AddressOf HandleButtonClick
AddHandler EditValueChanging, AddressOf HandleEditValueChanging
End Sub
Private Sub HandleEditValueChanging(sender As Object, e As ChangingEventArgs)
e.Cancel = True
End Sub
Private Sub HandleButtonClick(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
UpdateSelectedValues(oValues)
SelectedValues = oValues
End If
oForm.Dispose()
End Sub
Private Sub UpdateSelectedValues(Values As List(Of String))
If MultiSelect = True Then
Properties.DataSource = Values
Properties.NullText = IIf(Values.Count = 0, TEXT_NO_RECORDS, String.Format(TEXT_N_RECORDS, Values.Count))
Else
Text = Values.FirstOrDefault()
End If
End Sub
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 Point(Width, 0))
}
Return oForm
End Function
<DesignerSerializationVisibility(DesignerSerializationVisibility.Content)>
Public Shadows ReadOnly Property Properties As RepositoryItemLookupControl2
Get