add comboboxes for gridcontrol columns with sql commands

This commit is contained in:
Jonathan Jenne 2019-11-19 15:29:52 +01:00
parent 8b9b409769
commit d1fc3b8c12

View File

@ -1,8 +1,10 @@
Imports DD_LIB_Standards Imports System.ComponentModel
Imports DD_LIB_Standards
Imports DevExpress.Utils Imports DevExpress.Utils
Imports DevExpress.XtraEditors Imports DevExpress.XtraEditors
Imports DevExpress.XtraEditors.Controls Imports DevExpress.XtraEditors.Controls
Imports DevExpress.XtraEditors.NavigatorButtons Imports DevExpress.XtraEditors.NavigatorButtons
Imports DevExpress.XtraEditors.Repository
Imports DevExpress.XtraGrid Imports DevExpress.XtraGrid
Imports DevExpress.XtraGrid.Views.Base Imports DevExpress.XtraGrid.Views.Base
Imports DevExpress.XtraGrid.Views.Grid Imports DevExpress.XtraGrid.Views.Grid
@ -386,7 +388,7 @@ Public Class ClassControlCreator
oControl.ForceInitialize() oControl.ForceInitialize()
oView = oControl.DefaultView oView = oControl.MainView
oView.OptionsView.ShowGroupPanel = False oView.OptionsView.ShowGroupPanel = False
oControl.ContextMenu = Nothing oControl.ContextMenu = Nothing
@ -422,7 +424,11 @@ Public Class ClassControlCreator
End With End With
Dim oTables As New Dictionary(Of String, DataTable)
For Each oRow As DD_DMSLiteDataSet.TBPM_CONTROL_TABLERow In columns For Each oRow As DD_DMSLiteDataSet.TBPM_CONTROL_TABLERow In columns
' Create Columns in Datatable
Dim oColumn = New DataColumn() With { Dim oColumn = New DataColumn() With {
.DataType = GetType(String), .DataType = GetType(String),
.ColumnName = oRow.SPALTENNAME, .ColumnName = oRow.SPALTENNAME,
@ -431,11 +437,57 @@ Public Class ClassControlCreator
} }
oDatatable.Columns.Add(oColumn) oDatatable.Columns.Add(oColumn)
' Fetch and cache Combobox results
Dim oConnectionId As Integer = NotNull(oRow.Item("CONNECTION_ID"), 0)
Dim oSqlCommand As String = NotNull(oRow.Item("SQL_COMMAND"), "")
If oConnectionId > 0 And oSqlCommand <> "" Then
Try
Dim oComboboxDataTable As DataTable = ClassDatabase.Return_Datatable_ConId(oSqlCommand, oConnectionId)
oTables.Add(oRow.SPALTENNAME, oComboboxDataTable)
Catch ex As Exception
LOGGER.Warn("Could not load data for column {0} in control {1}", oRow.SPALTENNAME, oControl.Name)
LOGGER.Error(ex)
End Try
End If
Next Next
oControl.DataSource = oDatatable oControl.DataSource = oDatatable
oControl.RefreshDataSource()
oControl.ForceInitialize()
AddHandler oView.CellValueChanged, AddressOf HandleCellValueChanged AddHandler oView.CellValueChanged, AddressOf HandleCellValueChanged
AddHandler oView.CustomRowCellEdit, Sub(sender As Object, e As CustomRowCellEditEventArgs)
For Each oRow As DD_DMSLiteDataSet.TBPM_CONTROL_TABLERow In columns
If oRow.SPALTENNAME = e.Column.FieldName Then
If oTables.ContainsKey(e.Column.FieldName) Then
Dim oComboboxDataTable As DataTable = oTables.Item(e.Column.FieldName)
Dim oEditor As New RepositoryItemComboBox()
Dim oItems As New List(Of String)
oEditor.AutoComplete = True
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 In oComboboxDataTable.Rows
Dim oValue = oRow2.item(0)
oEditor.Items.Add(oValue)
oItems.Add(oValue)
Next
e.RepositoryItem = oEditor
End If
End If
Next
End Sub
Return oControl Return oControl
End Function End Function
@ -450,6 +502,8 @@ Public Class ClassControlCreator
Dim foo = 1 Dim foo = 1
End Function End Function
Public Shared Function CreateExistingLine(row As DataRow, designMode As Boolean) As LineLabel Public Shared Function CreateExistingLine(row As DataRow, designMode As Boolean) As LineLabel
Dim control As LineLabel = CreateBaseControl(New LineLabel(), row, designMode) Dim control As LineLabel = CreateBaseControl(New LineLabel(), row, designMode)
control.Text = "------------------------------" control.Text = "------------------------------"