This repository has been archived by the owner on Sep 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form1.vb
280 lines (264 loc) · 10.5 KB
/
Form1.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
Imports Microsoft.VisualBasic
Imports System
Imports System.Drawing
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Data
Imports DevExpress.XtraVerticalGrid
Imports DevExpress.XtraVerticalGrid.Rows
Namespace WindowsApplication409
''' <summary>
''' Summary description for Form1.
''' </summary>
Public Class Form1
Inherits System.Windows.Forms.Form
Private vGridControl1 As DevExpress.XtraVerticalGrid.VGridControl
Private rowAddress As DevExpress.XtraVerticalGrid.Rows.EditorRow
Private rowCity As DevExpress.XtraVerticalGrid.Rows.EditorRow
Private rowCompanyName As DevExpress.XtraVerticalGrid.Rows.EditorRow
Private rowContactName As DevExpress.XtraVerticalGrid.Rows.EditorRow
Private rowContactTitle As DevExpress.XtraVerticalGrid.Rows.EditorRow
Private rowCountry As DevExpress.XtraVerticalGrid.Rows.EditorRow
Private rowCustomerID As DevExpress.XtraVerticalGrid.Rows.EditorRow
Private rowFax As DevExpress.XtraVerticalGrid.Rows.EditorRow
Private rowPostalCode As DevExpress.XtraVerticalGrid.Rows.EditorRow
Private rowRegion As DevExpress.XtraVerticalGrid.Rows.EditorRow
Private WithEvents simpleButton1 As DevExpress.XtraEditors.SimpleButton
Private multiEditorRow1 As DevExpress.XtraVerticalGrid.Rows.MultiEditorRow
Private multiEditorRowProperties1 As MultiEditorRowProperties
Private multiEditorRowProperties2 As MultiEditorRowProperties
Private nwindDataSet As nwindDataSet
Private customersBindingSource As BindingSource
Private customersTableAdapter As nwindDataSetTableAdapters.CustomersTableAdapter
Private components As IContainer
Public Sub New()
'
' Required for Windows Form Designer support
'
InitializeComponent()
'
' TODO: Add any constructor code after InitializeComponent call
'
End Sub
''' <summary>
''' Clean up any resources being used.
''' </summary>
Protected Overrides Overloads Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If components IsNot Nothing Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
#Region "Windows Form Designer generated code"
''' <summary>
''' Required method for Designer support - do not modify
''' the contents of this method with the code editor.
''' </summary>
Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container()
Me.multiEditorRowProperties1 = New DevExpress.XtraVerticalGrid.Rows.MultiEditorRowProperties()
Me.multiEditorRowProperties2 = New DevExpress.XtraVerticalGrid.Rows.MultiEditorRowProperties()
Me.vGridControl1 = New DevExpress.XtraVerticalGrid.VGridControl()
Me.customersBindingSource = New System.Windows.Forms.BindingSource(Me.components)
Me.nwindDataSet = New nwindDataSet()
Me.rowAddress = New DevExpress.XtraVerticalGrid.Rows.EditorRow()
Me.rowCity = New DevExpress.XtraVerticalGrid.Rows.EditorRow()
Me.rowCompanyName = New DevExpress.XtraVerticalGrid.Rows.EditorRow()
Me.rowContactTitle = New DevExpress.XtraVerticalGrid.Rows.EditorRow()
Me.rowContactName = New DevExpress.XtraVerticalGrid.Rows.EditorRow()
Me.rowCountry = New DevExpress.XtraVerticalGrid.Rows.EditorRow()
Me.rowFax = New DevExpress.XtraVerticalGrid.Rows.EditorRow()
Me.multiEditorRow1 = New DevExpress.XtraVerticalGrid.Rows.MultiEditorRow()
Me.rowCustomerID = New DevExpress.XtraVerticalGrid.Rows.EditorRow()
Me.rowPostalCode = New DevExpress.XtraVerticalGrid.Rows.EditorRow()
Me.rowRegion = New DevExpress.XtraVerticalGrid.Rows.EditorRow()
Me.simpleButton1 = New DevExpress.XtraEditors.SimpleButton()
Me.customersTableAdapter = New nwindDataSetTableAdapters.CustomersTableAdapter()
CType(Me.vGridControl1, System.ComponentModel.ISupportInitialize).BeginInit()
CType(Me.customersBindingSource, System.ComponentModel.ISupportInitialize).BeginInit()
CType(Me.nwindDataSet, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
' multiEditorRowProperties1
'
Me.multiEditorRowProperties1.Caption = "Company"
Me.multiEditorRowProperties1.FieldName = "CompanyName"
'
' multiEditorRowProperties2
'
Me.multiEditorRowProperties2.Caption = "Phone"
Me.multiEditorRowProperties2.FieldName = "Phone"
'
' vGridControl1
'
Me.vGridControl1.DataSource = Me.customersBindingSource
Me.vGridControl1.LayoutStyle = DevExpress.XtraVerticalGrid.LayoutViewStyle.SingleRecordView
Me.vGridControl1.Location = New System.Drawing.Point(2, 12)
Me.vGridControl1.Name = "vGridControl1"
Me.vGridControl1.RecordWidth = 127
Me.vGridControl1.RowHeaderWidth = 73
Me.vGridControl1.Rows.AddRange(New DevExpress.XtraVerticalGrid.Rows.BaseRow() { Me.rowAddress, Me.rowContactTitle, Me.rowPostalCode})
Me.vGridControl1.ShowButtonMode = DevExpress.XtraVerticalGrid.ShowButtonModeEnum.ShowAlways
Me.vGridControl1.Size = New System.Drawing.Size(448, 400)
Me.vGridControl1.TabIndex = 0
'
' customersBindingSource
'
Me.customersBindingSource.DataMember = "Customers"
Me.customersBindingSource.DataSource = Me.nwindDataSet
'
' nwindDataSet
'
Me.nwindDataSet.DataSetName = "nwindDataSet"
Me.nwindDataSet.SchemaSerializationMode = System.Data.SchemaSerializationMode.IncludeSchema
'
' rowAddress
'
Me.rowAddress.ChildRows.AddRange(New DevExpress.XtraVerticalGrid.Rows.BaseRow() { Me.rowCity})
Me.rowAddress.Height = 16
Me.rowAddress.Name = "rowAddress"
Me.rowAddress.Properties.Caption = "Address"
Me.rowAddress.Properties.FieldName = "Address"
'
' rowCity
'
Me.rowCity.ChildRows.AddRange(New DevExpress.XtraVerticalGrid.Rows.BaseRow() { Me.rowCompanyName})
Me.rowCity.Name = "rowCity"
Me.rowCity.Properties.Caption = "City"
Me.rowCity.Properties.FieldName = "City"
'
' rowCompanyName
'
Me.rowCompanyName.Name = "rowCompanyName"
Me.rowCompanyName.Properties.Caption = "CompanyName"
Me.rowCompanyName.Properties.FieldName = "CompanyName"
'
' rowContactTitle
'
Me.rowContactTitle.ChildRows.AddRange(New DevExpress.XtraVerticalGrid.Rows.BaseRow() { Me.rowContactName, Me.rowCountry, Me.rowCustomerID})
Me.rowContactTitle.Name = "rowContactTitle"
Me.rowContactTitle.Properties.Caption = "ContactTitle"
Me.rowContactTitle.Properties.FieldName = "ContactTitle"
'
' rowContactName
'
Me.rowContactName.Name = "rowContactName"
Me.rowContactName.Properties.Caption = "ContactName"
Me.rowContactName.Properties.FieldName = "ContactName"
'
' rowCountry
'
Me.rowCountry.ChildRows.AddRange(New DevExpress.XtraVerticalGrid.Rows.BaseRow() { Me.rowFax})
Me.rowCountry.Name = "rowCountry"
Me.rowCountry.Properties.Caption = "Country"
Me.rowCountry.Properties.FieldName = "Country"
'
' rowFax
'
Me.rowFax.ChildRows.AddRange(New DevExpress.XtraVerticalGrid.Rows.BaseRow() { Me.multiEditorRow1})
Me.rowFax.Name = "rowFax"
Me.rowFax.Properties.Caption = "Fax"
Me.rowFax.Properties.FieldName = "Fax"
'
' multiEditorRow1
'
Me.multiEditorRow1.Name = "multiEditorRow1"
Me.multiEditorRow1.PropertiesCollection.AddRange(New DevExpress.XtraVerticalGrid.Rows.MultiEditorRowProperties() { Me.multiEditorRowProperties1, Me.multiEditorRowProperties2})
'
' rowCustomerID
'
Me.rowCustomerID.Name = "rowCustomerID"
Me.rowCustomerID.Properties.Caption = "CustomerID"
Me.rowCustomerID.Properties.FieldName = "CustomerID"
'
' rowPostalCode
'
Me.rowPostalCode.ChildRows.AddRange(New DevExpress.XtraVerticalGrid.Rows.BaseRow() { Me.rowRegion})
Me.rowPostalCode.Name = "rowPostalCode"
Me.rowPostalCode.Properties.Caption = "PostalCode"
Me.rowPostalCode.Properties.FieldName = "PostalCode"
'
' rowRegion
'
Me.rowRegion.Name = "rowRegion"
Me.rowRegion.Properties.Caption = "Region"
Me.rowRegion.Properties.FieldName = "Region"
'
' simpleButton1
'
Me.simpleButton1.Location = New System.Drawing.Point(160, 424)
Me.simpleButton1.Name = "simpleButton1"
Me.simpleButton1.Size = New System.Drawing.Size(75, 23)
Me.simpleButton1.TabIndex = 1
Me.simpleButton1.Text = "FindRow"
' Me.simpleButton1.Click += New System.EventHandler(Me.simpleButton1_Click);
'
' customersTableAdapter
'
Me.customersTableAdapter.ClearBeforeFill = True
'
' Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(515, 462)
Me.Controls.Add(Me.simpleButton1)
Me.Controls.Add(Me.vGridControl1)
Me.Name = "Form1"
Me.Text = "How to obtain a row object by FieldName in the XtraVerticalGrid"
' Me.Load += New System.EventHandler(Me.Form1_Load);
CType(Me.vGridControl1, System.ComponentModel.ISupportInitialize).EndInit()
CType(Me.customersBindingSource, System.ComponentModel.ISupportInitialize).EndInit()
CType(Me.nwindDataSet, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
End Sub
#End Region
''' <summary>
''' The main entry point for the application.
''' </summary>
<STAThread> _
Shared Sub Main()
Application.Run(New Form1())
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
' TODO: This line of code loads data into the 'nwindDataSet.Customers' table. You can move, or remove it, as needed.
Me.customersTableAdapter.Fill(Me.nwindDataSet.Customers)
End Sub
Private Sub simpleButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles simpleButton1.Click
vGridControl1.RowsIterator.DoOperation(New FindRowByFieldNameOperation("Phone"))
End Sub
End Class
Public Class FindRowByFieldNameOperation
Inherits RowOperation
Private fieldName As String
Private isRowFound As Boolean
Public Sub New(ByVal fieldName As String)
MyBase.New()
Me.fieldName = fieldName
isRowFound = False
End Sub
Private Sub FocusRow(ByVal row As BaseRow)
row.Grid.MakeRowVisible(row)
row.Grid.FocusedRow = row
isRowFound = True
End Sub
Public Overrides Sub Execute(ByVal row As BaseRow)
If TypeOf row Is MultiEditorRow Then
If (TryCast(row, MultiEditorRow)).PropertiesCollection(fieldName) IsNot Nothing Then
Dim mRow As MultiEditorRow = TryCast(row, MultiEditorRow)
FocusRow(row)
row.Grid.FocusedRecordCellIndex = mRow.PropertiesCollection.IndexOf(mRow.PropertiesCollection(fieldName))
Else
If row.Properties.FieldName = fieldName Then
FocusRow(row)
End If
End If
End If
End Sub
Public Overrides Function CanContinueIteration(ByVal row As BaseRow) As Boolean
Return Not isRowFound
End Function
End Class
End Namespace