LookupGrid: handle empty datasource better
This commit is contained in:
parent
7d8300a1db
commit
8e864d5b07
@ -10,61 +10,62 @@ Public Class frmLookupGrid
|
||||
Public Property DataSource As DataTable
|
||||
Public Property SelectedValues As List(Of String)
|
||||
|
||||
Private dataColumn As Integer
|
||||
Private dataSourceTemp As DataTable
|
||||
Private view As GridView
|
||||
Private grid As GridControl
|
||||
Private _DataColumn As Integer
|
||||
Private _DataSourceTemp As DataTable
|
||||
Private _View As GridView
|
||||
Private _Grid As GridControl
|
||||
|
||||
Private Sub frmLookupGrid_Load(sender As Object, e As EventArgs) Handles Me.Load
|
||||
view = viewLookup
|
||||
grid = gridLookup
|
||||
|
||||
If DataSource Is Nothing Then
|
||||
Exit Sub
|
||||
End If
|
||||
_View = viewLookup
|
||||
_Grid = gridLookup
|
||||
|
||||
' Original Datasource soll nicht verändert werden
|
||||
dataSourceTemp = DataSource.Copy()
|
||||
If DataSource Is Nothing Then
|
||||
_DataSourceTemp = New DataTable("TEMP")
|
||||
_DataSourceTemp.Columns.Add(New DataColumn("VALUE"))
|
||||
Else
|
||||
_DataSourceTemp = DataSource.Copy()
|
||||
End If
|
||||
|
||||
If MultiSelect Then
|
||||
If Not dataSourceTemp.Columns.Contains("SELECTED") Then
|
||||
If Not _DataSourceTemp.Columns.Contains("SELECTED") Then
|
||||
Dim selectedColumn = New DataColumn() With {
|
||||
.ColumnName = "SELECTED",
|
||||
.DataType = GetType(Boolean),
|
||||
.DefaultValue = False
|
||||
}
|
||||
dataSourceTemp.Columns.Add(selectedColumn)
|
||||
_DataSourceTemp.Columns.Add(selectedColumn)
|
||||
selectedColumn.SetOrdinal(0)
|
||||
End If
|
||||
End If
|
||||
|
||||
' Datasource setzen
|
||||
grid.DataSource = dataSourceTemp
|
||||
_Grid.DataSource = _DataSourceTemp
|
||||
|
||||
' Anzeige Eigeschaften setzen
|
||||
view.OptionsFind.Condition = DevExpress.Data.Filtering.FilterCondition.Contains
|
||||
view.OptionsFind.AlwaysVisible = True
|
||||
view.OptionsSelection.MultiSelect = False
|
||||
_View.OptionsFind.Condition = DevExpress.Data.Filtering.FilterCondition.Contains
|
||||
_View.OptionsFind.AlwaysVisible = True
|
||||
_View.OptionsSelection.MultiSelect = False
|
||||
|
||||
If MultiSelect Then
|
||||
' Selected Spalte anpassen
|
||||
Dim checkboxColumn = view.Columns.Item(0)
|
||||
checkboxColumn.Caption = " "
|
||||
checkboxColumn.MaxWidth = 10
|
||||
Dim oCheckboxColumn = _View.Columns.Item(0)
|
||||
oCheckboxColumn.Caption = " "
|
||||
oCheckboxColumn.MaxWidth = 10
|
||||
|
||||
Text = "Wählen Sie einen oder mehrere Werte:"
|
||||
dataColumn = 1
|
||||
_DataColumn = 1
|
||||
Else
|
||||
Text = "Wählen Sie einen Wert:"
|
||||
dataColumn = 0
|
||||
_DataColumn = 0
|
||||
End If
|
||||
|
||||
If AddNewValues Then
|
||||
view.OptionsBehavior.AllowAddRows = DevExpress.Utils.DefaultBoolean.True
|
||||
view.OptionsView.NewItemRowPosition = NewItemRowPosition.Top
|
||||
_View.OptionsBehavior.AllowAddRows = DevExpress.Utils.DefaultBoolean.True
|
||||
_View.OptionsView.NewItemRowPosition = NewItemRowPosition.Top
|
||||
Else
|
||||
view.OptionsBehavior.AllowAddRows = DevExpress.Utils.DefaultBoolean.False
|
||||
view.OptionsView.NewItemRowPosition = NewItemRowPosition.None
|
||||
_View.OptionsBehavior.AllowAddRows = DevExpress.Utils.DefaultBoolean.False
|
||||
_View.OptionsView.NewItemRowPosition = NewItemRowPosition.None
|
||||
End If
|
||||
|
||||
If SelectedValues Is Nothing Then
|
||||
@ -72,24 +73,24 @@ Public Class frmLookupGrid
|
||||
End If
|
||||
|
||||
' Bereits ausgewählte Werte im grid auswählen
|
||||
SyncItemsWithView(view)
|
||||
SyncItemsWithView(_View)
|
||||
|
||||
' Focus auf Find panel setzen
|
||||
view.ShowFindPanel()
|
||||
_View.ShowFindPanel()
|
||||
|
||||
' Spaltenbreite anpassen
|
||||
view.BestFitColumns()
|
||||
_View.BestFitColumns()
|
||||
End Sub
|
||||
|
||||
Private Sub SaveSelectedValues()
|
||||
' Filter vor dem Auslesen entfernen, damit alle Werte erfasst werden
|
||||
view.FindFilterText = String.Empty
|
||||
_View.FindFilterText = String.Empty
|
||||
|
||||
If MultiSelect Then
|
||||
Dim oValues As New List(Of String)
|
||||
|
||||
For oIndex = 0 To viewLookup.DataRowCount - 1
|
||||
Dim oRow As DataRow = view.GetDataRow(oIndex)
|
||||
Dim oRow As DataRow = _View.GetDataRow(oIndex)
|
||||
Dim oSelected As Boolean = oRow.Item(0)
|
||||
Dim oValue As Object = oRow.Item(1)
|
||||
|
||||
@ -105,8 +106,8 @@ Public Class frmLookupGrid
|
||||
|
||||
SelectedValues = oValues
|
||||
Else
|
||||
Dim oRowHandle As Integer = view.GetSelectedRows().ToList().FirstOrDefault()
|
||||
Dim oRow As DataRow = view.GetDataRow(oRowHandle)
|
||||
Dim oRowHandle As Integer = _View.GetSelectedRows().ToList().FirstOrDefault()
|
||||
Dim oRow As DataRow = _View.GetDataRow(oRowHandle)
|
||||
Dim oValues As New List(Of String)
|
||||
|
||||
If oRow IsNot Nothing Then
|
||||
@ -128,7 +129,7 @@ Public Class frmLookupGrid
|
||||
|
||||
If rowView IsNot Nothing Then
|
||||
Dim row As DataRow = rowView.Row
|
||||
Dim value = row.Item(dataColumn)
|
||||
Dim value = row.Item(_DataColumn)
|
||||
|
||||
If SelectedValues.Contains(value) Then
|
||||
If MultiSelect Then
|
||||
@ -187,8 +188,8 @@ Public Class frmLookupGrid
|
||||
End Sub
|
||||
|
||||
Private Sub viewLookup_ShowingEditor(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles viewLookup.ShowingEditor
|
||||
Dim rowHandleIsNewItemRow = (view.FocusedRowHandle = GridControl.NewItemRowHandle)
|
||||
Dim columnIsCheckboxColumn = view.FocusedColumn.FieldName = "SELECTED"
|
||||
Dim rowHandleIsNewItemRow = (_View.FocusedRowHandle = GridControl.NewItemRowHandle)
|
||||
Dim columnIsCheckboxColumn = _View.FocusedColumn.FieldName = "SELECTED"
|
||||
|
||||
' Prevent editing of Data Column/allow editing for Checkbox Column and NewValue Row
|
||||
If rowHandleIsNewItemRow Or columnIsCheckboxColumn Then
|
||||
@ -206,10 +207,10 @@ Public Class frmLookupGrid
|
||||
' If multiselect is true, check the current row
|
||||
' If multiselect is false, select the current row and close the window
|
||||
If MultiSelect = True Then
|
||||
Dim row As DataRow = view.GetDataRow(e.RowHandle)
|
||||
Dim row As DataRow = _View.GetDataRow(e.RowHandle)
|
||||
row.Item(0) = Not CBool(row.Item(0))
|
||||
Else
|
||||
Dim row As DataRow = view.GetDataRow(e.RowHandle)
|
||||
Dim row As DataRow = _View.GetDataRow(e.RowHandle)
|
||||
Dim value = row.Item(0)
|
||||
|
||||
SelectedValues = New List(Of String) From {value}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user