86 lines
2.6 KiB
VB.net
86 lines
2.6 KiB
VB.net
Imports DevExpress.XtraGrid
|
|
Imports DevExpress.XtraGrid.Views.Grid
|
|
Imports DigitalData.GUIs.Common
|
|
Imports DigitalData.Modules.Logging
|
|
Imports MultiTool.Shared
|
|
Imports MultiTool.Shared.Constants
|
|
|
|
Public Class GridLoader
|
|
Inherits BaseClass
|
|
|
|
Public Sub New(pLogConfig As LogConfig)
|
|
MyBase.New(pLogConfig)
|
|
End Sub
|
|
|
|
Public Function GetGridFromElement(pGrid As GridControl, pTable As Templates.Template.Table) As GridControl
|
|
pGrid.Name = pTable.Name
|
|
pGrid.ForceInitialize()
|
|
pGrid.MainView.PopulateColumns()
|
|
|
|
Dim oView As GridView = pGrid.DefaultView
|
|
oView.OptionsBehavior.ReadOnly = True
|
|
oView.OptionsBehavior.Editable = False
|
|
|
|
For Each oCol In pTable.Columns
|
|
Dim oVisibleIndex As Integer
|
|
|
|
If oCol.Config IsNot Nothing Then
|
|
If oCol.Config.IsVisible = False Then
|
|
oVisibleIndex = -1
|
|
Else
|
|
' If OrderKey is 0, set to a high number to
|
|
' push this column to the end of the grid
|
|
If oCol.Config.OrderKey = 0 Then
|
|
oVisibleIndex = 99
|
|
Else
|
|
oVisibleIndex = oCol.Config.OrderKey
|
|
End If
|
|
End If
|
|
Else
|
|
oVisibleIndex = 0
|
|
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 pGrid
|
|
End Function
|
|
|
|
Private Function GetColumnType(pColumn As Templates.Template.Column) As DevExpress.Data.UnboundColumnType
|
|
Select Case pColumn.DataType
|
|
Case ColumnType.Boolean
|
|
Return DevExpress.Data.UnboundColumnType.Boolean
|
|
|
|
Case ColumnType.Date
|
|
Return DevExpress.Data.UnboundColumnType.DateTime
|
|
|
|
Case ColumnType.Integer
|
|
Return DevExpress.Data.UnboundColumnType.Integer
|
|
|
|
Case ColumnType.Decimal
|
|
Return DevExpress.Data.UnboundColumnType.Decimal
|
|
|
|
Case Else
|
|
Return DevExpress.Data.UnboundColumnType.String
|
|
|
|
End Select
|
|
|
|
End Function
|
|
End Class
|