MultiTool/MultiTool.Form/GridLoader.vb
2021-10-29 10:37:04 +02:00

89 lines
2.5 KiB
VB.net

Imports DevExpress.XtraGrid
Imports DevExpress.XtraGrid.Views.Grid
Imports DigitalData.GUIs.Common
Imports DigitalData.Modules.Logging
Imports MultiTool.Shared
Public Class GridLoader
Inherits BaseClass
Public Sub New(pLogConfig As LogConfig)
MyBase.New(pLogConfig, pLogConfig.GetLogger())
End Sub
Public Function GetGridFromElement(pTable As Schemas.Schema.Table) As GridControl
Dim oGrid As New GridControl With {
.Dock = DockStyle.Fill,
.Name = pTable.Name
}
Dim oInvisibleColumns As New List(Of String) From {
"BELEGKEY",
"Zeilennummer",
"Belegart",
"Infotext",
"Leistungsdatum",
"Projektnummer",
"Auftragsreferenz",
"Laufnummer"
}
oGrid.ForceInitialize()
oGrid.MainView.PopulateColumns()
Dim oView As GridView = oGrid.DefaultView
oView.OptionsBehavior.ReadOnly = True
oView.OptionsBehavior.Editable = False
For Each oCol In pTable.Columns
Dim oVisibleIndex As Integer = 0
' Hide certain columns
If oInvisibleColumns.Contains(oCol.Name) Then
oVisibleIndex = -1
End If
Dim oColumn = New Columns.GridColumn With {
.Name = oCol.Name,
.Caption = oCol.Name,
.FieldName = oCol.Name,
.UnboundType = GetColumnType(oCol),
.VisibleIndex = oVisibleIndex
}
oView.Columns.Add(oColumn)
Next
oView.BestFitColumns()
Dim oGridBuilder As New GridBuilder(oView)
oGridBuilder.
WithDefaults().
WithReadOnlyOptions().
WithClipboardHandler()
Return oGrid
End Function
Private Function GetColumnType(pColumn As Schemas.Schema.Column)
Select Case pColumn.DataType
Case MultiTool.Shared.Constants.ColumnType.Boolean
Return DevExpress.Data.UnboundColumnType.Boolean
Case MultiTool.Shared.Constants.ColumnType.Date
Return DevExpress.Data.UnboundColumnType.DateTime
Case MultiTool.Shared.Constants.ColumnType.Integer
Return DevExpress.Data.UnboundColumnType.Integer
Case MultiTool.Shared.Constants.ColumnType.Decimal
Return DevExpress.Data.UnboundColumnType.Decimal
Case Else
Return DevExpress.Data.UnboundColumnType.String
End Select
End Function
End Class