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
121 lines (106 loc) · 4.6 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
Imports System
Imports System.Collections.Generic
Imports System.Data
Imports System.Windows.Forms
Imports System.ComponentModel
Namespace FilterMasterDetailGrid
Partial Public Class Form1
Inherits Form
Public Sub New()
InitializeComponent()
Dim bs As New BindingSource()
bs.DataSource = CreateObjectSource(3, 5)
gridControl1.DataSource = bs
Dim tempVar As New FilterHelper(gridView1, gridView2)
End Sub
Private Function CreateObjectSource(ByVal master As Integer, ByVal detail As Integer) As BindingList(Of Record)
Dim list As New BindingList(Of Record)()
For i As Integer = 0 To master - 1
Dim rec As New Record()
rec.Value = "Master " & i
rec.Detail = New BindingList(Of Record)()
For j As Integer = 0 To detail - 1
Dim childRec As New Record()
childRec.Value = "Child " & i & " " & + j
rec.Detail.Add(childRec)
Next j
list.Add(rec)
Next i
Return list
End Function
Private Class Record
Private _value As String
Private _detail As BindingList(Of Record)
Public Property Value() As String
Get
Return _value
End Get
Set(ByVal value As String)
_value = value
End Set
End Property
Public Property Detail() As BindingList(Of Record)
Get
Return _detail
End Get
Set(ByVal value As BindingList(Of Record))
_detail = value
End Set
End Property
End Class
Private Function CreateTable(ByVal RowCount As Integer) As DataTable
Dim tbl As New DataTable("Parent")
tbl.Columns.Add("Name", GetType(String))
tbl.Columns.Add("Number", GetType(Integer))
tbl.Columns.Add("Date", GetType(Date))
tbl.Columns.Add("DETAILID", GetType(Integer))
For i As Integer = 0 To RowCount - 1
tbl.Rows.Add(New Object() { String.Format("Name{0}", i), 3 - i, Date.Now.AddDays(i), i })
Next i
Return tbl
End Function
Private Function CreateDet1Table(ByVal RowCount As Integer) As DataTable
Dim tbl As New DataTable("Det1")
tbl.Columns.Add("Name", GetType(String))
tbl.Columns.Add("ID", GetType(Integer))
For j As Integer = 0 To 4
For i As Integer = 0 To RowCount - 1
tbl.Rows.Add(New Object() { String.Format("Name{0}", j + (i Mod 2) * 5), i })
Next i
Next j
Return tbl
End Function
Private Function GetMasterDetail() As DataSet
Dim ds As New DataSet("TestDS")
ds.Tables.Add(CreateTable(20))
ds.Tables.Add(CreateDet1Table(20))
Dim parentColumn As DataColumn = ds.Tables("Parent").Columns("DETAILID")
Dim childColumn As DataColumn = ds.Tables("Det1").Columns("ID")
ds.Relations.Add(New DataRelation("Detail", parentColumn, childColumn))
Return ds
End Function
Private Sub gridView2_ColumnFilterChanged(ByVal sender As Object, ByVal e As EventArgs) Handles gridView2.ColumnFilterChanged
gridView1.DataController.RefreshData()
End Sub
Private Sub simpleButton1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles simpleButton1.Click
gridView2.ActiveFilter.Clear()
End Sub
Private Sub simpleButton2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles simpleButton2.Click
gridControl1.DataSource = GetMasterDetail().Tables("Parent")
gridView1.PopulateColumns()
gridView2.PopulateColumns()
End Sub
Private Sub simpleButton3_Click(ByVal sender As Object, ByVal e As EventArgs) Handles simpleButton3.Click
gridControl1.DataSource = CreateObjectSource(3, 5)
gridView1.PopulateColumns()
gridView2.PopulateColumns()
End Sub
Private Sub simpleButton4_Click(ByVal sender As Object, ByVal e As EventArgs) Handles simpleButton4.Click
Dim bs As New BindingSource()
bs.DataSource = CreateObjectSource(3, 5)
gridControl1.DataSource = bs
gridView1.PopulateColumns()
gridView2.PopulateColumns()
End Sub
End Class
End Namespace