-
Notifications
You must be signed in to change notification settings - Fork 0
/
Code.vb
74 lines (65 loc) · 2.21 KB
/
Code.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
Imports DevExpress.DataAccess.ObjectBinding
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Threading.Tasks
Namespace ObjectDataSourceSnippets
Public Class BindingToParametrizedConstructor
Private Sub ObjectDataSourceInitialization()
Dim objds As New ObjectDataSource()
objds.Name = "ObjectDataSource1"
objds.BeginUpdate()
objds.DataMember = "Items"
objds.DataSource = GetType(BusinessObject)
objds.EndUpdate()
'this line of code allows passing a parameter value to a parametrized constructor of an underlying data source object
Dim parameter = New DevExpress.DataAccess.ObjectBinding.Parameter("p1", GetType(Integer), 3)
objds.Constructor = New DevExpress.DataAccess.ObjectBinding.ObjectConstructorInfo(parameter)
End Sub
Public Class BusinessObject
Public Property Items() As SampleItems
Public Sub New(ByVal p1 As Integer)
Items = New SampleItems(p1)
End Sub
End Class
Public Class SampleItems
Inherits List(Of SampleItem)
Public Sub New()
Me.New(10)
End Sub
Public Sub New(ByVal itemNumber As Integer)
For i As Integer = 0 To itemNumber - 1
Add(New SampleItem() With {.Name = i.ToString()})
Next i
End Sub
End Class
Public Class SampleItem
Public Property Name() As String
End Class
End Class
Public Class BindingToMethod
Private Sub ObjectDataSourceInitialization()
Dim objds As New DevExpress.DataAccess.ObjectBinding.ObjectDataSource()
objds.Name = "ObjectDataSource1"
objds.BeginUpdate()
objds.DataMember = "GetData"
objds.DataSource = GetType(SampleItem)
objds.EndUpdate()
Dim parameter = New DevExpress.DataAccess.ObjectBinding.Parameter("value", GetType(Integer), 3)
objds.Parameters.Add(parameter)
'this line of code is required to obtain the data source object schema
objds.Fill()
End Sub
Public Class SampleItem
Public Property Name() As String
Public Shared Function GetData(ByVal value As Integer) As List(Of SampleItem)
Dim items As New List(Of SampleItem)()
For i As Integer = 0 To value - 1
items.Add(New SampleItem() With {.Name = i.ToString()})
Next i
Return items
End Function
End Class
End Class
End Namespace