jj: dynamic controls depending on multiselect

This commit is contained in:
Jonathan Jenne 2018-10-30 15:37:41 +01:00
parent 7fc347ae05
commit ff7e16d5c6
3 changed files with 91 additions and 29 deletions

View File

@ -22,41 +22,17 @@ Partial Class Grid
'Das Bearbeiten mit dem Code-Editor ist nicht möglich.
<System.Diagnostics.DebuggerStepThrough()>
Private Sub InitializeComponent()
Me.TextBox1 = New System.Windows.Forms.TextBox()
Me.btnOpenForm = New System.Windows.Forms.Button()
Me.SuspendLayout()
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(0, 0)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(231, 20)
Me.TextBox1.TabIndex = 0
'
'btnOpenForm
'
Me.btnOpenForm.Location = New System.Drawing.Point(237, 0)
Me.btnOpenForm.Name = "btnOpenForm"
Me.btnOpenForm.Size = New System.Drawing.Size(30, 20)
Me.btnOpenForm.TabIndex = 1
Me.btnOpenForm.Text = "..."
Me.btnOpenForm.UseVisualStyleBackColor = True
'
'Grid
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.AutoSize = True
Me.BackColor = System.Drawing.Color.Transparent
Me.Controls.Add(Me.btnOpenForm)
Me.Controls.Add(Me.TextBox1)
Me.Name = "Grid"
Me.Size = New System.Drawing.Size(270, 23)
Me.Size = New System.Drawing.Size(270, 35)
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
Friend WithEvents TextBox1 As Windows.Forms.TextBox
Friend WithEvents btnOpenForm As Windows.Forms.Button
End Class

View File

@ -1,5 +1,7 @@

Imports System.ComponentModel
Imports DevExpress.XtraEditors
Imports DevExpress.XtraEditors.Controls
Public Class Grid
<Category("Einstellungen"), Description("Gibt an, ob mehrere Werte auswählbar sind"), DefaultValue(False)>
@ -13,16 +15,97 @@ Public Class Grid
<Browsable(False)>
Public Property SelectedValues As New List(Of String)
Private Sub btnOpenForm_Click(sender As Object, e As EventArgs) Handles btnOpenForm.Click
Dim frm As New frmLookupGrid() With {
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
.SelectedValues = SelectedValues,
.StartPosition = Windows.Forms.FormStartPosition.Manual,
.Location = PointToScreen(New System.Drawing.Point(Width, 0))
}
frm.ShowDialog()
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

View File

@ -137,6 +137,9 @@ Public Class frmLookupGrid
Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
SelectedValues.Clear()
DialogResult = DialogResult.Cancel
Close()
End Sub
Private Sub gridLookup_KeyUp(sender As Object, e As KeyEventArgs) Handles gridLookup.KeyUp