LookupGrid: Add ReadOnly option
This commit is contained in:
parent
ecdf35f6fe
commit
10f87536df
@ -1,15 +1,174 @@
|
|||||||
Imports System.ComponentModel
|
Imports System.ComponentModel
|
||||||
Imports System.Drawing
|
Imports System.Drawing
|
||||||
|
Imports System.Windows.Forms
|
||||||
|
Imports DevExpress.Accessibility
|
||||||
Imports DevExpress.XtraEditors
|
Imports DevExpress.XtraEditors
|
||||||
Imports DevExpress.XtraEditors.Drawing
|
Imports DevExpress.XtraEditors.Drawing
|
||||||
Imports DevExpress.XtraEditors.Registrator
|
Imports DevExpress.XtraEditors.Registrator
|
||||||
Imports DevExpress.XtraEditors.Repository
|
Imports DevExpress.XtraEditors.Repository
|
||||||
Imports DevExpress.XtraEditors.ViewInfo
|
Imports DevExpress.XtraEditors.ViewInfo
|
||||||
Imports DevExpress.XtraEditors.Popup
|
|
||||||
Imports DevExpress.Accessibility
|
|
||||||
Imports DevExpress.XtraEditors.Controls
|
Imports DevExpress.XtraEditors.Controls
|
||||||
|
|
||||||
|
<ToolboxItem(True)>
|
||||||
|
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)
|
||||||
|
Get
|
||||||
|
Return _SelectedValues
|
||||||
|
End Get
|
||||||
|
Set(value As List(Of String))
|
||||||
|
_SelectedValues = value
|
||||||
|
UpdateSelectedValues(value)
|
||||||
|
End Set
|
||||||
|
End Property
|
||||||
|
Public Overloads Property [ReadOnly] As Boolean
|
||||||
|
Get
|
||||||
|
Return _ReadOnly
|
||||||
|
End Get
|
||||||
|
Set(value As Boolean)
|
||||||
|
SetButtonVisibility(Not value)
|
||||||
|
_ReadOnly = value
|
||||||
|
End Set
|
||||||
|
End Property
|
||||||
|
|
||||||
|
Private ReadOnly _LookupFormButton As EditorButton
|
||||||
|
|
||||||
|
Private Const TAG_BUTTON_LOOKUP_FORM = "openLookupForm"
|
||||||
|
Private Const TEXT_NO_RECORDS = "Keine Datensätze ausgewählt"
|
||||||
|
Private Const TEXT_ONE_RECORD = "Ein Datensatz ausgewählt"
|
||||||
|
Private Const TEXT_N_RECORDS = "{0} Datensätze ausgewählt"
|
||||||
|
|
||||||
|
Private _SelectedValues As List(Of String)
|
||||||
|
Private _ReadOnly As Boolean = False
|
||||||
|
|
||||||
|
Shared Sub New()
|
||||||
|
RepositoryItemLookupControl2.RegisterLookupControl2()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
Public Sub New()
|
||||||
|
MyClass.New(MultiSelect:=False)
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
Public Sub New(MultiSelect As Boolean)
|
||||||
|
_LookupFormButton = New EditorButton() With {
|
||||||
|
.Kind = ButtonPredefines.Ellipsis,
|
||||||
|
.Tag = TAG_BUTTON_LOOKUP_FORM
|
||||||
|
}
|
||||||
|
|
||||||
|
Properties.Buttons.AddRange({_LookupFormButton})
|
||||||
|
|
||||||
|
AddHandler ButtonClick, AddressOf HandleButtonClick
|
||||||
|
AddHandler EditValueChanging, AddressOf HandleEditValueChanging
|
||||||
|
AddHandler QueryPopUp, AddressOf HandleQueryPopup
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
Private Sub SetButtonVisibility(Visible As Boolean)
|
||||||
|
Dim oButton As EditorButton = Properties.Buttons.
|
||||||
|
Where(Function(b) b.Tag = TAG_BUTTON_LOOKUP_FORM).
|
||||||
|
FirstOrDefault()
|
||||||
|
|
||||||
|
If oButton IsNot Nothing Then
|
||||||
|
oButton.Visible = Visible
|
||||||
|
End If
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
''' <summary>
|
||||||
|
''' Prevents popup from opening when multiselect is false
|
||||||
|
''' </summary>
|
||||||
|
Private Sub HandleQueryPopup(sender As Object, e As CancelEventArgs)
|
||||||
|
If MultiSelect = False Then
|
||||||
|
e.Cancel = True
|
||||||
|
End If
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
''' <summary>
|
||||||
|
''' Prevents Editvalue changing when multiselect is true
|
||||||
|
''' </summary>
|
||||||
|
Private Sub HandleEditValueChanging(sender As Object, e As ChangingEventArgs)
|
||||||
|
If MultiSelect Then
|
||||||
|
e.Cancel = True
|
||||||
|
End If
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
''' <summary>
|
||||||
|
''' Handles opening frmLookup when ellipsis button is clicked
|
||||||
|
''' </summary>
|
||||||
|
Private Sub HandleButtonClick(sender As Object, e As ButtonPressedEventArgs)
|
||||||
|
Select Case e.Button.Tag
|
||||||
|
Case TAG_BUTTON_LOOKUP_FORM
|
||||||
|
Using oForm = GetLookupForm()
|
||||||
|
Dim oResult = oForm.ShowDialog()
|
||||||
|
|
||||||
|
If oResult = Windows.Forms.DialogResult.OK Then
|
||||||
|
Dim oValues = oForm.SelectedValues
|
||||||
|
|
||||||
|
UpdateSelectedValues(oValues)
|
||||||
|
SelectedValues = oValues
|
||||||
|
ElseIf oResult = Windows.Forms.DialogResult.Cancel Then
|
||||||
|
Dim oValues = New List(Of String)
|
||||||
|
|
||||||
|
UpdateSelectedValues(oValues)
|
||||||
|
SelectedValues = oValues
|
||||||
|
End If
|
||||||
|
End Using
|
||||||
|
End Select
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
Private Sub UpdateSelectedValues(Values As List(Of String))
|
||||||
|
If Values Is Nothing Then
|
||||||
|
Exit Sub
|
||||||
|
End If
|
||||||
|
|
||||||
|
If MultiSelect = True Then
|
||||||
|
Properties.DataSource = Values
|
||||||
|
|
||||||
|
Select Case Values.Count
|
||||||
|
Case 0
|
||||||
|
Properties.NullText = TEXT_NO_RECORDS
|
||||||
|
Case 1
|
||||||
|
Properties.NullText = TEXT_ONE_RECORD
|
||||||
|
Case Else
|
||||||
|
Properties.NullText = String.Format(TEXT_N_RECORDS, Values.Count)
|
||||||
|
End Select
|
||||||
|
Else
|
||||||
|
Properties.NullText = Values.FirstOrDefault()
|
||||||
|
Text = Values.FirstOrDefault()
|
||||||
|
EditValue = Nothing
|
||||||
|
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 = FormStartPosition.Manual,
|
||||||
|
.Location = PointToScreen(New Point(Width, 0))
|
||||||
|
}
|
||||||
|
|
||||||
|
Return oForm
|
||||||
|
End Function
|
||||||
|
|
||||||
|
<DesignerSerializationVisibility(DesignerSerializationVisibility.Content)>
|
||||||
|
Public Shadows ReadOnly Property Properties As RepositoryItemLookupControl2
|
||||||
|
Get
|
||||||
|
Return TryCast(MyBase.Properties, RepositoryItemLookupControl2)
|
||||||
|
End Get
|
||||||
|
End Property
|
||||||
|
|
||||||
|
Public Overrides ReadOnly Property EditorTypeName As String
|
||||||
|
Get
|
||||||
|
Return RepositoryItemLookupControl2.CustomEditName
|
||||||
|
End Get
|
||||||
|
End Property
|
||||||
|
End Class
|
||||||
|
|
||||||
<UserRepositoryItem("RegisterLookupControl2")>
|
<UserRepositoryItem("RegisterLookupControl2")>
|
||||||
Public Class RepositoryItemLookupControl2
|
Public Class RepositoryItemLookupControl2
|
||||||
@ -45,147 +204,3 @@ Public Class RepositoryItemLookupControl2
|
|||||||
End Try
|
End Try
|
||||||
End Sub
|
End Sub
|
||||||
End Class
|
End Class
|
||||||
|
|
||||||
<ToolboxItem(True)>
|
|
||||||
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)
|
|
||||||
Get
|
|
||||||
Return _SelectedValues
|
|
||||||
End Get
|
|
||||||
Set(value As List(Of String))
|
|
||||||
_SelectedValues = value
|
|
||||||
UpdateSelectedValues(value)
|
|
||||||
End Set
|
|
||||||
End Property
|
|
||||||
|
|
||||||
Private LookupFormButton As EditorButton
|
|
||||||
Private DropdownButton As EditorButton
|
|
||||||
|
|
||||||
Private Const TAG_BUTTON_LOOKUP_FORM = "openLookupForm"
|
|
||||||
|
|
||||||
Private Const TEXT_NO_RECORDS = "Keine Datensätze ausgewählt"
|
|
||||||
Private Const TEXT_ONE_RECORD = "Ein Datensatz ausgewählt"
|
|
||||||
Private Const TEXT_N_RECORDS = "{0} Datensätze ausgewählt"
|
|
||||||
|
|
||||||
Private _SelectedValues As List(Of String)
|
|
||||||
|
|
||||||
Shared Sub New()
|
|
||||||
RepositoryItemLookupControl2.RegisterLookupControl2()
|
|
||||||
End Sub
|
|
||||||
|
|
||||||
Public Sub New()
|
|
||||||
MyClass.New(MultiSelect:=False)
|
|
||||||
End Sub
|
|
||||||
|
|
||||||
Public Sub New(MultiSelect As Boolean)
|
|
||||||
LookupFormButton = New EditorButton() With {
|
|
||||||
.Kind = ButtonPredefines.Ellipsis,
|
|
||||||
.Tag = TAG_BUTTON_LOOKUP_FORM
|
|
||||||
}
|
|
||||||
|
|
||||||
Properties.Buttons.AddRange({LookupFormButton})
|
|
||||||
|
|
||||||
AddHandler ButtonClick, AddressOf HandleButtonClick
|
|
||||||
AddHandler EditValueChanging, AddressOf HandleEditValueChanging
|
|
||||||
AddHandler QueryPopUp, AddressOf HandleQueryPopup
|
|
||||||
End Sub
|
|
||||||
|
|
||||||
''' <summary>
|
|
||||||
''' Prevents popup from opening when multiselect is false
|
|
||||||
''' </summary>
|
|
||||||
Private Sub HandleQueryPopup(sender As Object, e As CancelEventArgs)
|
|
||||||
If MultiSelect = False Then
|
|
||||||
e.Cancel = True
|
|
||||||
End If
|
|
||||||
End Sub
|
|
||||||
|
|
||||||
''' <summary>
|
|
||||||
''' Prevents Editvalue changing when multiselect is true
|
|
||||||
''' </summary>
|
|
||||||
Private Sub HandleEditValueChanging(sender As Object, e As ChangingEventArgs)
|
|
||||||
If MultiSelect Then
|
|
||||||
e.Cancel = True
|
|
||||||
End If
|
|
||||||
End Sub
|
|
||||||
|
|
||||||
''' <summary>
|
|
||||||
''' Handles opening frmLookup when ellipsis button is clicked
|
|
||||||
''' </summary>
|
|
||||||
Private Sub HandleButtonClick(sender As Object, e As ButtonPressedEventArgs)
|
|
||||||
Select Case e.Button.Tag
|
|
||||||
Case TAG_BUTTON_LOOKUP_FORM
|
|
||||||
Dim oForm As frmLookupGrid = GetLookupForm()
|
|
||||||
Dim oResult = oForm.ShowDialog()
|
|
||||||
|
|
||||||
If oResult = Windows.Forms.DialogResult.OK Then
|
|
||||||
Dim oValues = oForm.SelectedValues
|
|
||||||
|
|
||||||
UpdateSelectedValues(oValues)
|
|
||||||
SelectedValues = oValues
|
|
||||||
ElseIf oResult = Windows.Forms.DialogResult.Cancel Then
|
|
||||||
Dim oValues = New List(Of String)
|
|
||||||
|
|
||||||
UpdateSelectedValues(oValues)
|
|
||||||
SelectedValues = oValues
|
|
||||||
End If
|
|
||||||
|
|
||||||
oForm.Dispose()
|
|
||||||
End Select
|
|
||||||
End Sub
|
|
||||||
|
|
||||||
Private Sub UpdateSelectedValues(Values As List(Of String))
|
|
||||||
If Values Is Nothing Then
|
|
||||||
Exit Sub
|
|
||||||
End If
|
|
||||||
|
|
||||||
If MultiSelect = True Then
|
|
||||||
Properties.DataSource = Values
|
|
||||||
|
|
||||||
Select Case Values.Count
|
|
||||||
Case 0
|
|
||||||
Properties.NullText = TEXT_NO_RECORDS
|
|
||||||
Case 1
|
|
||||||
Properties.NullText = TEXT_ONE_RECORD
|
|
||||||
Case Else
|
|
||||||
Properties.NullText = String.Format(TEXT_N_RECORDS, Values.Count)
|
|
||||||
End Select
|
|
||||||
Else
|
|
||||||
Properties.NullText = Values.FirstOrDefault()
|
|
||||||
Text = Values.FirstOrDefault()
|
|
||||||
EditValue = Nothing
|
|
||||||
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
|
|
||||||
Return TryCast(MyBase.Properties, RepositoryItemLookupControl2)
|
|
||||||
End Get
|
|
||||||
End Property
|
|
||||||
|
|
||||||
Public Overrides ReadOnly Property EditorTypeName As String
|
|
||||||
Get
|
|
||||||
Return RepositoryItemLookupControl2.CustomEditName
|
|
||||||
End Get
|
|
||||||
End Property
|
|
||||||
End Class
|
|
||||||
|
|||||||
@ -1,7 +1,4 @@
|
|||||||
|
Public Class Form1
|
||||||
|
|
||||||
|
|
||||||
Public Class Form1
|
|
||||||
Private _Datasource As New List(Of String) From {"Foo", "bar", "baz", "quux"}
|
Private _Datasource As New List(Of String) From {"Foo", "bar", "baz", "quux"}
|
||||||
|
|
||||||
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
|
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
|
||||||
@ -11,6 +8,7 @@ Public Class Form1
|
|||||||
|
|
||||||
LookupControl.DataSource = oDatatable
|
LookupControl.DataSource = oDatatable
|
||||||
LookupControl.SelectedValues = oSelectedValues
|
LookupControl.SelectedValues = oSelectedValues
|
||||||
|
LookupControl.ReadOnly = True
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
Private Function GetDatatable() As DataTable
|
Private Function GetDatatable() As DataTable
|
||||||
@ -27,11 +25,10 @@ Public Class Form1
|
|||||||
oDatatable.Rows.Add(oRow)
|
oDatatable.Rows.Add(oRow)
|
||||||
Next
|
Next
|
||||||
|
|
||||||
|
|
||||||
Return oDatatable
|
Return oDatatable
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
|
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
|
||||||
MsgBox(LookupControl.SelectedValues.Count)
|
LookupControl.ReadOnly = Not LookupControl.ReadOnly
|
||||||
End Sub
|
End Sub
|
||||||
End Class
|
End Class
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user