Fix editor not updating correctly when datasource/depending control changes

This commit is contained in:
Jonathan Jenne
2021-10-04 13:26:50 +02:00
parent 9d123727d4
commit e0845b9999
2 changed files with 47 additions and 138 deletions

View File

@@ -517,132 +517,13 @@ Public Class ClassControlCreator
AddHandler oView.CustomRowCellEdit, Sub(sender As Object, e As CustomRowCellEditEventArgs) AddHandler oView.CustomRowCellEdit, Sub(sender As Object, e As CustomRowCellEditEventArgs)
Try Try
For Each oRow As DataRow In DT_MY_COLUMNS.Rows For Each oRow As DataRow In DT_MY_COLUMNS.Rows
If oRow.Item("SPALTENNAME") <> e.Column.FieldName Then Dim oColumnName = oRow.Item("SPALTENNAME")
Continue For Dim oEditorExists = GridTables_TestEditorExistsByControlAndColumn(oControlId, oColumnName)
End If
If Not GridTables.Item(oControlId).ContainsKey(e.Column.FieldName) Then
Continue For
End If
Dim oEditor = GridTables.Item(oControlId).Item(e.Column.FieldName)
If oColumnName = e.Column.FieldName And oEditorExists Then
Dim oEditor = GridTables.Item(oControlId).Item(oColumnName)
e.RepositoryItem = oEditor e.RepositoryItem = oEditor
End If
#Region "Old Stuff"
'Dim oComboboxDataTable As DataTable = GridTables.Item(oControlId).Item(e.Column.FieldName)
'If oComboboxDataTable Is Nothing Then
' Throw New ApplicationException($"ComboboxTable for Column {e.Column.FieldName} is empty.")
'End If
'If oRow.Item("ADVANCED_LOOKUP") Then
' Dim oEditor = New RepositoryItemLookupControl3
' If oComboboxDataTable IsNot Nothing Then
' oEditor.DisplayMember = oComboboxDataTable.Columns.Item(0).ColumnName
' oEditor.ValueMember = oComboboxDataTable.Columns.Item(0).ColumnName
' oEditor.DataSource = oComboboxDataTable
' End If
' 'AddHandler oEditor.SelectedValuesChanged, Sub(_sender As Object, _e As List(Of String))
' ' oView.PostEditor()
' ' End Sub
' 'AddHandler oEditor.BeforePopup, Sub(_sender As Object, _e As EventArgs)
' ' MsgBox("oEditor.BeforePopup")
' ' Dim oConnectionId As Integer = NotNull(oRow.Item("CONNECTION_ID"), 0)
' ' Dim oSqlCommand As String = NotNull(oRow.Item("SQL_COMMAND"), "")
' ' oSqlCommand = clsPatterns.ReplaceAllValues(oSqlCommand, pPanel, True)
' ' Dim oTable = ClassDatabase.Return_Datatable_ConId(oSqlCommand, oConnectionId)
' ' oEditor.DataSource = oTable
' ' oEditor.DisplayMember = oComboboxDataTable.Columns.Item(0).ColumnName
' ' oEditor.ValueMember = oComboboxDataTable.Columns.Item(0).ColumnName
' ' End Sub
' 'AddHandler oEditor.QueryPopUp, Sub()
' ' MsgBox("oEditor.QueryPopUp")
' ' End Sub
' 'AddHandler oEditor.Popup, Sub()
' ' MsgBox("oEditor.Popup")
' ' End Sub
' 'AddHandler oEditor.ButtonClick, Sub()
' ' MsgBox("oEditor.ButtonClick")
' ' End Sub
' AddHandler oEditor.ButtonPressed, Sub(_sender As Object, _e As EventArgs)
' Dim oEditor2 = DirectCast(_sender, LookupControl3)
' 'MsgBox("oEditor.ButtonPressed")
' Dim oConnectionId As Integer = NotNull(oRow.Item("CONNECTION_ID"), 0)
' Dim oSqlCommand As String = NotNull(oRow.Item("SQL_COMMAND"), "")
' oSqlCommand = clsPatterns.ReplaceAllValues(oSqlCommand, pPanel, True)
' Dim oTable = ClassDatabase.Return_Datatable_ConId(oSqlCommand, oConnectionId)
' If oTable IsNot Nothing Then
' oEditor2.Properties.ValueMember = oTable.Columns.Item(0).ColumnName
' oEditor2.Properties.DisplayMember = oTable.Columns.Item(0).ColumnName
' oEditor2.Properties.DataSource = oTable
' oEditor2.DoValidate(PopupCloseMode.Normal)
' End If
' End Sub
' e.RepositoryItem = oEditor
'Else
' If oComboboxDataTable Is Nothing Then
' Dim oConnectionId As Integer = NotNull(oRow.Item("CONNECTION_ID"), 0)
' Dim oSqlCommand As String = NotNull(oRow.Item("SQL_COMMAND"), "")
' oSqlCommand = clsPatterns.ReplaceAllValues(oSqlCommand, pPanel, True)
' oComboboxDataTable = ClassDatabase.Return_Datatable_ConId(oSqlCommand, oConnectionId)
' End If
' If oComboboxDataTable Is Nothing Then
' Continue For
' End If
' Dim oEditor = New RepositoryItemComboBox()
' Dim oItems As New List(Of String)
' AddHandler oEditor.Validating, Sub(_sender As ComboBoxEdit, _e As CancelEventArgs)
' If oItems.Contains(_sender.EditValue) Then
' _e.Cancel = False
' Else
' _e.Cancel = True
' End If
' End Sub
' For Each oRow2 As DataRow In oComboboxDataTable.Rows
' Dim oValue = oRow2.Item(0)
' Try
' oValue &= $" | {oRow2.Item(1)}"
' Catch ex As Exception
' End Try
' oEditor.Items.Add(oValue)
' oItems.Add(oValue)
' Next
' e.RepositoryItem = oEditor
'End If
#End Region
Next Next
Catch ex As Exception Catch ex As Exception
LOGGER.Warn("Error in CustomRowCellEdit for [{0}]", e.CellValue) LOGGER.Warn("Error in CustomRowCellEdit for [{0}]", e.CellValue)
@@ -849,10 +730,6 @@ Public Class ClassControlCreator
End Sub End Sub
Public Shared Function GridTables_GetRepositoryItemForColumn(pColumnName As String, pDataTable As DataTable, pIsAdvancedLookup As Boolean) As RepositoryItem Public Shared Function GridTables_GetRepositoryItemForColumn(pColumnName As String, pDataTable As DataTable, pIsAdvancedLookup As Boolean) As RepositoryItem
If pDataTable Is Nothing Then
Return Nothing
End If
If pIsAdvancedLookup Then If pIsAdvancedLookup Then
Dim oEditor = New RepositoryItemLookupControl3 Dim oEditor = New RepositoryItemLookupControl3
@@ -876,6 +753,8 @@ Public Class ClassControlCreator
End If End If
End Sub End Sub
If pDataTable IsNot Nothing Then
For Each oRow2 As DataRow In pDataTable.Rows For Each oRow2 As DataRow In pDataTable.Rows
Dim oValue = oRow2.Item(0) Dim oValue = oRow2.Item(0)
@@ -887,8 +766,23 @@ Public Class ClassControlCreator
oEditor.Items.Add(oValue) oEditor.Items.Add(oValue)
oItems.Add(oValue) oItems.Add(oValue)
Next Next
End If
Return oEditor Return oEditor
End If End If
End Function End Function
Private Shared Function GridTables_TestEditorExistsByControlAndColumn(oControlId As Integer, pColumn As String) As Boolean
If GridTables.ContainsKey(oControlId) Then
Dim oContainsKey = GridTables.Item(oControlId).ContainsKey(pColumn)
If oContainsKey AndAlso GridTables.Item(oControlId).Item(pColumn) IsNot Nothing Then
Return True
Else
Return False
End If
Else
Return False
End If
End Function
End Class End Class

View File

@@ -1147,6 +1147,21 @@ Public Class frmValidator
ClassControlCreator.GridTables_CacheDatatableForColumn(oControlId, oColumnName, oSqlStatement, oConnectionId, oAdvancedLookup) ClassControlCreator.GridTables_CacheDatatableForColumn(oControlId, oColumnName, oSqlStatement, oConnectionId, oAdvancedLookup)
' === Block to force setting the editor for GridColumns
For Each oControl As Control In pnldesigner.Controls
Try
Dim oMeta = DirectCast(oControl.Tag, ClassControlCreator.ControlMetadata)
If oMeta.Guid = oControlId AndAlso TypeOf oControl Is GridControl Then
Dim oGrid As GridControl = DirectCast(oControl, GridControl)
DirectCast(oGrid.FocusedView, GridView).FocusInvalidRow()
Exit For
End If
Catch ex As Exception
LOGGER.Error(ex)
End Try
Next
' === End
End If End If
Catch ex As Exception Catch ex As Exception
LOGGER.Error(ex) LOGGER.Error(ex)