-
Notifications
You must be signed in to change notification settings - Fork 1
/
Form1.vb
88 lines (75 loc) · 4.39 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
Imports DevExpress.XtraEditors
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Drawing
Imports System.Windows.Forms
Namespace Lookup_ComboboxMode
Public Partial Class Form1
Inherits Form
Public Sub New()
InitializeComponent()
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
initLookupEdit()
initGridLookupEdit()
End Sub
Private Sub initLookupEdit()
AddHandler lookUpEdit1.EditValueChanged, AddressOf LookUpEdit1_EditValueChanged
lookUpEdit1.Properties.NullText = "(select or type value)"
Dim colors As String() = New String() {"Yellow", "Red", "Green", "Black", "White"}
lookUpEdit1.Properties.DataSource = colors
lookUpEdit1.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.Standard
lookUpEdit1.Properties.AcceptEditorTextAsNewValue = DevExpress.Utils.DefaultBoolean.Default 'Default is equivalent to True for LookupEdit control
End Sub
Private Sub initGridLookupEdit()
AddHandler gridLookUpEdit1.EditValueChanged, AddressOf LookUpEdit1_EditValueChanged
gridLookUpEdit1.Properties.NullText = "(select or type value)"
Dim products As List(Of Product) = New List(Of Product) From {New Product() With {.ProductName = "Chang"}, New Product() With {.ProductName = "Ipoh Coffee"}, New Product() With {.ProductName = "Ravioli Angelo"}, New Product() With {.ProductName = "Filo Mix"}, New Product() With {.ProductName = "Tunnbröd"}, New Product() With {.ProductName = "Konbu"}, New Product() With {.ProductName = "Boston Crab Meat"}}
gridLookUpEdit1.Properties.DataSource = products
gridLookUpEdit1.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.Standard
gridLookUpEdit1.Properties.AcceptEditorTextAsNewValue = DevExpress.Utils.DefaultBoolean.True
gridLookUpEdit1.Properties.ValueMember = "ProductName"
gridLookUpEdit1.Properties.DisplayMember = gridLookUpEdit1.Properties.ValueMember
AddHandler gridLookUpEdit1.ProcessNewValue, AddressOf GridLookUpEdit1_ProcessNewValue
End Sub
Private labelDictionaryCore As Dictionary(Of LookUpEditBase, LabelControl)
Private ReadOnly Property labelDictionary As Dictionary(Of LookUpEditBase, LabelControl)
Get
If labelDictionaryCore Is Nothing Then
labelDictionaryCore = New Dictionary(Of LookUpEditBase, LabelControl)()
labelDictionaryCore.Add(lookUpEdit1, labelControl1)
labelDictionaryCore.Add(gridLookUpEdit1, labelControl2)
End If
Return labelDictionaryCore
End Get
End Property
Private Sub LookUpEdit1_EditValueChanged(ByVal sender As Object, ByVal e As EventArgs)
'Display lookup editor's current value.
Dim lookupEditor As LookUpEditBase = TryCast(sender, LookUpEditBase)
If lookupEditor Is Nothing Then Return
Dim label As LabelControl = labelDictionary(lookupEditor)
If label Is Nothing Then Return
If lookupEditor.EditValue Is Nothing Then
label.Text = "Current EditValue: null"
Else
label.Text = "Current EditValue: " & lookupEditor.EditValue.ToString()
End If
End Sub
Private Sub GridLookUpEdit1_ProcessNewValue(ByVal sender As Object, ByVal e As DevExpress.XtraEditors.Controls.ProcessNewValueEventArgs)
'Add new values to GridLookUpEdit control's DataSource.
Dim gridLookup As GridLookUpEdit = TryCast(sender, GridLookUpEdit)
If e.DisplayValue Is Nothing Then Return
Dim newValue As String = e.DisplayValue.ToString()
If Equals(newValue, String.Empty) Then Return
If MessageBox.Show(Me, "Add '" & newValue & "' to list?", "Confirm", MessageBoxButtons.YesNo) = DialogResult.Yes Then
Dim ds As List(Of Product) = TryCast(gridLookup.Properties.DataSource, List(Of Product))
ds.Add(New Product With {.ProductName = newValue})
e.Handled = True
End If
End Sub
End Class
Public Class Product
Public Property ProductName As String
End Class
End Namespace