From ba1806466df1f5467f392875609a156a78e8b7ec Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Thu, 29 Aug 2019 11:12:59 +0200 Subject: [PATCH] LookupGrid: version 0.2.0.0 --- Controls.LookupGrid/LookupControl2.vb | 44 +++++++------------ .../My Project/AssemblyInfo.vb | 2 +- Controls.LookupGrid/frmLookupGrid.vb | 25 ++++++----- LookupControlGui/Form1.Designer.vb | 6 ++- LookupControlGui/Form1.resx | 18 ++++++++ LookupControlGui/Form1.vb | 6 ++- 6 files changed, 59 insertions(+), 42 deletions(-) diff --git a/Controls.LookupGrid/LookupControl2.vb b/Controls.LookupGrid/LookupControl2.vb index 4fe33233..99463d1c 100644 --- a/Controls.LookupGrid/LookupControl2.vb +++ b/Controls.LookupGrid/LookupControl2.vb @@ -16,10 +16,20 @@ Public Class LookupControl2 Public Delegate Sub SelectedValuesChangedHandler(sender As Object, SelectedValues As List(Of String)) Public Event SelectedValuesChanged As SelectedValuesChangedHandler - Public Property MultiSelect As Boolean Public Property AllowAddNewValues As Boolean Public Property PreventDuplicates As Boolean Public Property DataSource As DataTable + + Public Property MultiSelect As Boolean + Get + Return _Multiselect + End Get + Set(value As Boolean) + SetDropdownButtonEnabled(value) + _MultiSelect = value + End Set + End Property + Public Property SelectedValues As List(Of String) Get Return _SelectedValues @@ -28,6 +38,7 @@ Public Class LookupControl2 UpdateSelectedValues(value) End Set End Property + Public Overloads Property [ReadOnly] As Boolean Get Return _ReadOnly @@ -47,8 +58,10 @@ Public Class LookupControl2 Private Const TEXT_N_RECORDS = "{0} Datensätze ausgewählt" Private _SelectedValues As New List(Of String) - Friend WithEvents fProperties As RepositoryItemGridLookUpEdit - Friend WithEvents fPropertiesView As DevExpress.XtraGrid.Views.Grid.GridView + Private _MultiSelect As Boolean + + Friend WithEvents GridView1 As DevExpress.XtraGrid.Views.Grid.GridView + Friend WithEvents GridView2 As DevExpress.XtraGrid.Views.Grid.GridView Private _ReadOnly As Boolean = False Shared Sub New() @@ -183,31 +196,6 @@ Public Class LookupControl2 Return RepositoryItemLookupControl2.CustomEditName End Get End Property - - 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/Controls.LookupGrid/My Project/AssemblyInfo.vb b/Controls.LookupGrid/My Project/AssemblyInfo.vb index 2eb9f91d..fbb24296 100644 --- a/Controls.LookupGrid/My Project/AssemblyInfo.vb +++ b/Controls.LookupGrid/My Project/AssemblyInfo.vb @@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices ' übernehmen, indem Sie "*" eingeben: ' - + diff --git a/Controls.LookupGrid/frmLookupGrid.vb b/Controls.LookupGrid/frmLookupGrid.vb index f6cf41f8..0a013eb3 100644 --- a/Controls.LookupGrid/frmLookupGrid.vb +++ b/Controls.LookupGrid/frmLookupGrid.vb @@ -10,6 +10,7 @@ Public Class frmLookupGrid Public Property SelectedValues As List(Of String) Private dataColumn As Integer + Private dataSourceTemp As DataTable Private view As GridView Private grid As GridControl @@ -17,25 +18,27 @@ Public Class frmLookupGrid view = viewLookup grid = gridLookup - If DataSource Is Nothing Then Exit Sub End If + ' Original Datasource soll nicht verändert werden + dataSourceTemp = DataSource.Copy() + If MultiSelect Then - If Not DataSource.Columns.Contains("SELECTED") Then + If Not dataSourceTemp.Columns.Contains("SELECTED") Then Dim selectedColumn = New DataColumn() With { - .ColumnName = "SELECTED", - .DataType = GetType(Boolean), - .DefaultValue = False - } - DataSource.Columns.Add(selectedColumn) + .ColumnName = "SELECTED", + .DataType = GetType(Boolean), + .DefaultValue = False + } + dataSourceTemp.Columns.Add(selectedColumn) selectedColumn.SetOrdinal(0) End If End If ' Datasource setzen - grid.DataSource = DataSource + grid.DataSource = dataSourceTemp ' Anzeige Eigeschaften setzen view.OptionsFind.AlwaysVisible = True @@ -71,7 +74,9 @@ Public Class frmLookupGrid ' Focus auf Find panel setzen view.ShowFindPanel() - Me.BringToFront() + + ' Spaltenbreite anpassen + view.BestFitColumns() End Sub Private Sub SyncItemsWithView(view As GridView) @@ -195,6 +200,6 @@ Public Class frmLookupGrid End Sub Private Sub frmLookupGrid_Shown(sender As Object, e As EventArgs) Handles Me.Shown - Me.BringToFront() + BringToFront() End Sub End Class \ No newline at end of file diff --git a/LookupControlGui/Form1.Designer.vb b/LookupControlGui/Form1.Designer.vb index 825a143a..101e9107 100644 --- a/LookupControlGui/Form1.Designer.vb +++ b/LookupControlGui/Form1.Designer.vb @@ -89,6 +89,8 @@ Partial Class Form1 Me.LookupControl.Name = "LookupControl" Me.LookupControl.PreventDuplicates = False Me.LookupControl.Properties.Buttons.AddRange(New DevExpress.XtraEditors.Controls.EditorButton() {New DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo, "", -1, True, True, False, EditorButtonImageOptions1, New DevExpress.Utils.KeyShortcut(System.Windows.Forms.Keys.None), SerializableAppearanceObject1, SerializableAppearanceObject2, SerializableAppearanceObject3, SerializableAppearanceObject4, "", "openDropdown", Nothing, DevExpress.Utils.ToolTipAnchor.[Default]), New DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Ellipsis, "", -1, True, True, False, EditorButtonImageOptions2, New DevExpress.Utils.KeyShortcut(System.Windows.Forms.Keys.None), SerializableAppearanceObject5, SerializableAppearanceObject6, SerializableAppearanceObject7, SerializableAppearanceObject8, "", "openLookupForm", Nothing, DevExpress.Utils.ToolTipAnchor.[Default])}) + Me.LookupControl.Properties.DataSource = CType(resources.GetObject("LookupControl.Properties.DataSource"), Object) + Me.LookupControl.Properties.NullText = "Keine Datensätze ausgewählt" Me.LookupControl.Properties.PopupView = Me.LookupControl21View Me.LookupControl.SelectedValues = CType(resources.GetObject("LookupControl.SelectedValues"), System.Collections.Generic.List(Of String)) Me.LookupControl.Size = New System.Drawing.Size(342, 20) @@ -119,6 +121,8 @@ Partial Class Form1 Me.LookupControl21.Name = "LookupControl21" Me.LookupControl21.PreventDuplicates = False Me.LookupControl21.Properties.Buttons.AddRange(New DevExpress.XtraEditors.Controls.EditorButton() {New DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo, "", -1, True, True, False, EditorButtonImageOptions3, New DevExpress.Utils.KeyShortcut(System.Windows.Forms.Keys.None), SerializableAppearanceObject9, SerializableAppearanceObject10, SerializableAppearanceObject11, SerializableAppearanceObject12, "", "openDropdown", Nothing, DevExpress.Utils.ToolTipAnchor.[Default]), New DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Ellipsis, "", -1, True, True, False, EditorButtonImageOptions4, New DevExpress.Utils.KeyShortcut(System.Windows.Forms.Keys.None), SerializableAppearanceObject13, SerializableAppearanceObject14, SerializableAppearanceObject15, SerializableAppearanceObject16, "", "openLookupForm", Nothing, DevExpress.Utils.ToolTipAnchor.[Default])}) + Me.LookupControl21.Properties.DataSource = CType(resources.GetObject("LookupControl21.Properties.DataSource"), Object) + Me.LookupControl21.Properties.NullText = "Keine Datensätze ausgewählt" Me.LookupControl21.Properties.PopupView = Me.GridView1 Me.LookupControl21.SelectedValues = CType(resources.GetObject("LookupControl21.SelectedValues"), System.Collections.Generic.List(Of String)) Me.LookupControl21.Size = New System.Drawing.Size(342, 20) @@ -150,7 +154,7 @@ Partial Class Form1 Me.LookupControl22.PreventDuplicates = False Me.LookupControl22.Properties.Buttons.AddRange(New DevExpress.XtraEditors.Controls.EditorButton() {New DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo, "", -1, True, True, False, EditorButtonImageOptions5, New DevExpress.Utils.KeyShortcut(System.Windows.Forms.Keys.None), SerializableAppearanceObject17, SerializableAppearanceObject18, SerializableAppearanceObject19, SerializableAppearanceObject20, "", "openDropdown", Nothing, DevExpress.Utils.ToolTipAnchor.[Default]), New DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Ellipsis, "", -1, True, True, False, EditorButtonImageOptions6, New DevExpress.Utils.KeyShortcut(System.Windows.Forms.Keys.None), SerializableAppearanceObject21, SerializableAppearanceObject22, SerializableAppearanceObject23, SerializableAppearanceObject24, "", "openLookupForm", Nothing, DevExpress.Utils.ToolTipAnchor.[Default])}) Me.LookupControl22.Properties.DataSource = CType(resources.GetObject("LookupControl22.Properties.DataSource"), Object) - Me.LookupControl22.Properties.NullText = "Keine Datensätze ausgewählt" + Me.LookupControl22.Properties.NullText = "" Me.LookupControl22.Properties.PopupView = Me.GridView2 Me.LookupControl22.SelectedValues = CType(resources.GetObject("LookupControl22.SelectedValues"), System.Collections.Generic.List(Of String)) Me.LookupControl22.Size = New System.Drawing.Size(342, 20) diff --git a/LookupControlGui/Form1.resx b/LookupControlGui/Form1.resx index fe049d32..e500039b 100644 --- a/LookupControlGui/Form1.resx +++ b/LookupControlGui/Form1.resx @@ -117,6 +117,15 @@ System.Resources.ResXResourceWriter, System.Windows.For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kxpc3RgMVtbU3lzdGVtLlN0cmluZwMAAAAGX2l0 + ZW1zBV9zaXplCF92ZXJzaW9uBgAACAgCAAAACQMAAAAAAAAAAAAAABEDAAAAAAAAAAs= diff --git a/LookupControlGui/Form1.vb b/LookupControlGui/Form1.vb index 0e52611c..3e3672b3 100644 --- a/LookupControlGui/Form1.vb +++ b/LookupControlGui/Form1.vb @@ -18,7 +18,7 @@ LookupControl22.ReadOnly = False LookupControl22.MultiSelect = False - LookupControl22.SelectedValues = New List(Of String) From {"", Nothing, "LOL"} + LookupControl22.SelectedValues = New List(Of String) From {"", Nothing, "LOL", "Foo"} AddHandler LookupControl.SelectedValuesChanged, Sub(_sender As Object, SelectedValues As List(Of String)) MsgBox("Selected Values: " & String.Join(",", SelectedValues.ToArray)) @@ -36,7 +36,8 @@ Private Function GetDatatable() As DataTable Dim oDatatable As New DataTable Dim oColumns As New List(Of DataColumn) From { - New DataColumn("Col1", GetType(String)) + New DataColumn("Col1", GetType(String)), + New DataColumn("Col2", GetType(String)) } oDatatable.Columns.AddRange(oColumns.ToArray) @@ -44,6 +45,7 @@ For Each Item In _Datasource Dim oRow = oDatatable.NewRow() oRow.Item("Col1") = Item + oRow.Item("Col2") = Item & "_" & "SomeLong Random(String) !!!111einself" oDatatable.Rows.Add(oRow) Next