-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMasterDetailHelper.vb
157 lines (139 loc) · 5.04 KB
/
MasterDetailHelper.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports DevExpress.XtraGrid.Views.Base
Imports DevExpress.XtraGrid
Imports DevExpress.XtraGrid.Columns
Imports DevExpress.XtraEditors.Repository
Imports DevExpress.XtraEditors
Imports System.Collections
Imports DevExpress.XtraGrid.Views.Card
Imports DevExpress.XtraGrid.Views.Grid
Imports DevExpress.XtraGrid.Views.Layout
Imports DevExpress.XtraGrid.Views.Base.ViewInfo
Imports System.Drawing
Imports System.Windows.Forms
Imports DevExpress.XtraGrid.Views.Grid.ViewInfo
Imports DevExpress.Utils.Win
Imports DevExpress.XtraEditors.Popup
Namespace WindowsApplication3
Public Enum ViewType
Grid
Layout
Card
End Enum
Public Class MasterDetailHelper
'INSTANT VB NOTE: The variable detailView was renamed since Visual Basic does not allow variables and other class members to have the same name:
Private view, detailView_Renamed As ColumnView
'INSTANT VB NOTE: The variable viewType was renamed since Visual Basic does not allow variables and other class members to have the same name:
Private viewType_Renamed As ViewType
'INSTANT VB NOTE: The variable detailGrid was renamed since Visual Basic does not allow variables and other class members to have the same name:
Private detailGrid_Renamed As GridControl
Public Sub New(ByVal view As ColumnView, ByVal viewType As ViewType)
Me.view = view
Me.viewType_Renamed = viewType
End Sub
Public ReadOnly Property DetailGrid() As GridControl
Get
If detailGrid_Renamed Is Nothing Then
detailGrid_Renamed = CreateGrid()
detailGrid_Renamed.MainView = DetailView
End If
Return detailGrid_Renamed
End Get
End Property
Public ReadOnly Property DetailView() As ColumnView
Get
If detailView_Renamed Is Nothing Then
detailView_Renamed = CreateView()
End If
Return detailView_Renamed
End Get
End Property
Public Property ViewType() As ViewType
Get
Return viewType_Renamed
End Get
Set(ByVal value As ViewType)
If viewType_Renamed <> value Then
viewType_Renamed = value
detailView_Renamed = Nothing
DetailGrid.MainView = DetailView
End If
End Set
End Property
Public Sub CreateDetail()
SetColumnEdit(CreateColumn())
End Sub
Private Function CreateGrid() As GridControl
Dim grid As New GridControl()
grid.Dock = System.Windows.Forms.DockStyle.Fill
Return grid
End Function
Private Function CreateView() As ColumnView
If viewType_Renamed = WindowsApplication3.ViewType.Card Then
detailView_Renamed = New CardView(DetailGrid)
ElseIf viewType_Renamed = WindowsApplication3.ViewType.Grid Then
detailView_Renamed = New GridView(DetailGrid)
CType(detailView_Renamed, GridView).OptionsView.ShowGroupPanel = False
Else
detailView_Renamed = New LayoutView(DetailGrid)
End If
Return detailView_Renamed
End Function
Private Function CreateColumn() As GridColumn
Dim column As GridColumn = view.Columns.AddField("Detail")
column.Visible = True
column.VisibleIndex = view.Columns.Count
Return column
End Function
Private Sub SetColumnEdit(ByVal column As GridColumn)
column.ColumnEdit = CreateItem()
End Sub
Private Function CreateItem() As RepositoryItemPopupContainerEdit
Dim item As New RepositoryItemPopupContainerEdit()
item.PopupControl = CreatePopupControl()
item.ShowPopupShadow = False
item.ShowPopupCloseButton = item.ShowPopupShadow
item.PopupSizeable = False
item.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.HideTextEditor
AddHandler item.QueryPopUp, AddressOf OnPopup
AddHandler item.CloseUp, AddressOf OnCloseUp
view.GridControl.RepositoryItems.Add(item)
Return item
End Function
Private Function CreatePopupControl() As PopupContainerControl
Dim popupControl As New PopupContainerControl()
popupControl.Controls.Add(DetailGrid)
Return popupControl
End Function
Private Sub OnPopup(ByVal sender As Object, ByVal e As EventArgs)
DetailGrid.BeginUpdate()
Try
DetailGrid.DataSource = Nothing
DetailGrid.DataSource = GetDetailData()
Finally
DetailGrid.EndUpdate()
End Try
Dim edit As PopupContainerEdit = TryCast(sender, PopupContainerEdit)
If edit.Properties.PopupControl.Parent Is Nothing Then
edit.Properties.PopupControl.Parent = edit.FindForm()
End If
DetailGrid.ForceInitialize()
edit.Properties.PopupFormSize = CalcDetailViewSize()
End Sub
Private Function GetDetailData() As IList
Return view.DataController.GetDetailList(view.FocusedRowHandle, 0)
End Function
Private Function CalcDetailViewSize() As System.Drawing.Size
Dim viewInfo As ColumnViewInfo = TryCast(DetailView.GetViewInfo(), ColumnViewInfo)
Dim rect As New Rectangle(0, 0, view.GridControl.ClientSize.Width, DetailView.DetailHeight)
rect.Height = viewInfo.CalcRealViewHeight(rect, True) + 5
Return rect.Size
End Function
Private Sub OnCloseUp(ByVal sender As Object, ByVal e As DevExpress.XtraEditors.Controls.CloseUpEventArgs)
DetailView.PostEditor()
detailView_Renamed.UpdateCurrentRow()
End Sub
End Class
End Namespace