From 21ee4416efffdc67907b5805db3e5f4c38b26d5b Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Fri, 22 Mar 2019 13:44:20 +0100 Subject: [PATCH] First Pass of new LookupControl --- LookupGrid/GridLookupEditExOLD.resx | 123 -------------------------- LookupGrid/GridLookupEditExOLD.vb | 131 ---------------------------- LookupGrid/LookupControl.vbproj | 7 -- LookupGrid/LookupControl2.vb | 65 ++++++++++++++ LookupGrid/LookupCreator.vb | 3 - 5 files changed, 65 insertions(+), 264 deletions(-) delete mode 100644 LookupGrid/GridLookupEditExOLD.resx delete mode 100644 LookupGrid/GridLookupEditExOLD.vb delete mode 100644 LookupGrid/LookupCreator.vb diff --git a/LookupGrid/GridLookupEditExOLD.resx b/LookupGrid/GridLookupEditExOLD.resx deleted file mode 100644 index e5858cc2..00000000 --- a/LookupGrid/GridLookupEditExOLD.resx +++ /dev/null @@ -1,123 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - False - - \ No newline at end of file diff --git a/LookupGrid/GridLookupEditExOLD.vb b/LookupGrid/GridLookupEditExOLD.vb deleted file mode 100644 index c5274973..00000000 --- a/LookupGrid/GridLookupEditExOLD.vb +++ /dev/null @@ -1,131 +0,0 @@ -Imports System.ComponentModel -Imports DevExpress.XtraEditors -Imports DevExpress.XtraEditors.Controls -Imports DevExpress.XtraEditors.Repository - -Public Class GridLookupEditExOLD - 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) - Get - If _selectedValues Is Nothing Then - Return New List(Of String) - End If - - Return _selectedValues - End Get - Set(value As List(Of String)) - _selectedValues = value - - UpdateSelectedValues(value) - End Set - End Property - - Private _selectedValues As List(Of String) - - Private Const TAG_BUTTON_LOOKUP_FORM = "openLookupForm" - Private Const TEXT_NO_RECORDS = "Keine Datensätze ausgewählt" - Friend WithEvents fProperties As RepositoryItemGridLookUpEdit - Friend WithEvents fPropertiesView As DevExpress.XtraGrid.Views.Grid.GridView - Private Const TEXT_N_RECORDS = "{0} Datensätze ausgewählt" - - Public Sub New() - Properties.View.OptionsBehavior.ReadOnly = True - Properties.View.OptionsBehavior.Editable = False - Properties.View.OptionsView.ShowColumnHeaders = False - Properties.PopupFormSize = New System.Drawing.Size(Properties.PopupFormSize.Width, 100) - - ' If single select, remove dropdown button - If MultiSelect = False Then - Properties.Buttons.Clear() - End If - - Properties.Buttons.Add(New EditorButton() With { - .Kind = ButtonPredefines.Ellipsis, - .Tag = TAG_BUTTON_LOOKUP_FORM - }) - - 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 System.Drawing.Point(Width, 0)) - } - - Return oForm - End Function - - 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 Sub GridLookupEditEx_EditValueChanging(sender As Object, e As ChangingEventArgs) Handles Me.EditValueChanging - If MultiSelect Then - e.Cancel = True - End If - 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 - - UpdateSelectedValues(oValues) - - SelectedValues = oValues - End If - - oForm.Dispose() - End Sub - - Private Sub InitializeComponent() - Me.fProperties = New DevExpress.XtraEditors.Repository.RepositoryItemGridLookUpEdit() - Me.fPropertiesView = New DevExpress.XtraGrid.Views.Grid.GridView() - CType(Me.fProperties, System.ComponentModel.ISupportInitialize).BeginInit() - CType(Me.fPropertiesView, System.ComponentModel.ISupportInitialize).BeginInit() - Me.SuspendLayout() - ' - 'fProperties - ' - Me.fProperties.Buttons.AddRange(New DevExpress.XtraEditors.Controls.EditorButton() {New DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo)}) - Me.fProperties.Name = "fProperties" - Me.fProperties.PopupView = Me.fPropertiesView - ' - 'fPropertiesView - ' - Me.fPropertiesView.FocusRectStyle = DevExpress.XtraGrid.Views.Grid.DrawFocusRectStyle.RowFocus - Me.fPropertiesView.Name = "fPropertiesView" - Me.fPropertiesView.OptionsSelection.EnableAppearanceFocusedCell = False - Me.fPropertiesView.OptionsView.ShowGroupPanel = False - CType(Me.fProperties, System.ComponentModel.ISupportInitialize).EndInit() - CType(Me.fPropertiesView, System.ComponentModel.ISupportInitialize).EndInit() - Me.ResumeLayout(False) - - End Sub -End Class diff --git a/LookupGrid/LookupControl.vbproj b/LookupGrid/LookupControl.vbproj index a5a03a59..9ebcc41b 100644 --- a/LookupGrid/LookupControl.vbproj +++ b/LookupGrid/LookupControl.vbproj @@ -105,9 +105,6 @@ Form - - Component - LookupControl.vb @@ -117,7 +114,6 @@ Component - @@ -152,9 +148,6 @@ frmLookupGrid.vb - - GridLookupEditExOLD.vb - LookupControl.vb diff --git a/LookupGrid/LookupControl2.vb b/LookupGrid/LookupControl2.vb index 7908bc17..ea3f8de0 100644 --- a/LookupGrid/LookupControl2.vb +++ b/LookupGrid/LookupControl2.vb @@ -7,6 +7,9 @@ Imports DevExpress.XtraEditors.Repository Imports DevExpress.XtraEditors.ViewInfo Imports DevExpress.XtraEditors.Popup Imports DevExpress.Accessibility +Imports DevExpress.XtraEditors.Controls + + 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 + Public Shadows ReadOnly Property Properties As RepositoryItemLookupControl2 Get diff --git a/LookupGrid/LookupCreator.vb b/LookupGrid/LookupCreator.vb deleted file mode 100644 index 6f9a206e..00000000 --- a/LookupGrid/LookupCreator.vb +++ /dev/null @@ -1,3 +0,0 @@ -Public Class LookupCreator - -End Class