-
Notifications
You must be signed in to change notification settings - Fork 1
/
Products.vb
67 lines (49 loc) · 2.73 KB
/
Products.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
Imports DevExpress.Mvvm.DataAnnotations
Imports DevExpress.Xpf.PropertyGrid.Internal
Imports System.Collections
Imports System.Collections.Generic
Imports System.ComponentModel
Namespace pgrid_dictionary
Public Class Supplier
Public Property FirstName As String
Public Property LastName As String
Public Property Phone As String
End Class
Public Class Product
Public Property ProductName As String
Public Property Country As String
Public Property City As String
Public Property UnitPrice As Double
Public Property Quantity As Integer
<DictionaryKey1()>
Public Property Tags As IDictionary(Of String, Supplier) = New Dictionary(Of String, Supplier)()
End Class
Public Class DictionaryKey1Attribute
Inherits NewItemInstanceInitializerAttribute
Public Sub New()
MyBase.New(GetType(Supplier))
End Sub
Public Overrides Function CreateInstance(ByVal context As ITypeDescriptorContext, ByVal dictionary As IEnumerable) As KeyValuePair(Of Object, Object)?
Dim testObject = TryCast(CType(context, DescriptorContext).Value, IDictionary(Of String, Supplier))
Dim key As Integer = testObject.Keys.Count
While testObject.Keys.Contains(key.ToString())
key += 1
End While
Return New KeyValuePair(Of Object, Object)(key.ToString(), New Supplier())
End Function
End Class
Public Class ProductList
Inherits List(Of Product)
Public Sub New()
MyBase.New()
Add(New Product() With {.ProductName = "Chang", .Country = "UK", .City = "Cowes", .UnitPrice = 19, .Quantity = 10})
Add(New Product() With {.ProductName = "Gravad lax", .Country = "Italy", .City = "Reggio Emilia", .UnitPrice = 12.5, .Quantity = 16})
Add(New Product() With {.ProductName = "Ravioli Angelo", .Country = "Brazil", .City = "Rio de Janeiro", .UnitPrice = 19, .Quantity = 12})
Add(New Product() With {.ProductName = "Tarte au sucre", .Country = "Germany", .City = "QUICK-Stop", .UnitPrice = 22, .Quantity = 50})
Add(New Product() With {.ProductName = "Steeleye Stout", .Country = "USA", .City = "Reggio Emilia", .UnitPrice = 18, .Quantity = 20})
Add(New Product() With {.ProductName = "Pavlova", .Country = "Austria", .City = "Graz", .UnitPrice = 21, .Quantity = 52})
Add(New Product() With {.ProductName = "Longlife Tofu", .Country = "USA", .City = "Boise", .UnitPrice = 7.75, .Quantity = 120})
Add(New Product() With {.ProductName = "Alice Mutton", .Country = "Canada", .City = "Tsawwassen", .UnitPrice = 44, .Quantity = 16})
End Sub
End Class
End Namespace