-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm1.vb
62 lines (54 loc) · 2.41 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
Imports System
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Windows.Forms
Imports DevExpress.XtraEditors
Imports DevExpress.XtraEditors.Controls
Imports DevExpress.XtraEditors.Repository
Namespace NotFoundValue
Public Partial Class Form1
Inherits Form
Public Sub New()
InitializeComponent()
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
Dim tblLookUp As DataTable = New DataTable()
tblLookUp.Columns.Add("Code", GetType(Integer))
tblLookUp.Columns.Add("Name")
tblLookUp.Rows.Add(New Object() {1, "one"})
tblLookUp.Rows.Add(New Object() {2, "two"})
Dim tblGrid As DataTable = New DataTable()
tblGrid.Columns.Add("Number", GetType(Integer))
For i As Integer = 0 To 3 - 1
tblGrid.Rows.Add(New Object() {i})
Next
gridControl1.DataSource = tblGrid
Dim editor As RepositoryItemLookUpEdit = TryCast(gridControl1.RepositoryItems.Add("LookUpEdit"), RepositoryItemLookUpEdit)
editor.DataSource = tblLookUp
editor.ValueMember = "Code"
editor.DisplayMember = "Name"
AddHandler editor.CustomDisplayText, New CustomDisplayTextEventHandler(AddressOf RepositoryItemLookUpEdit_CustomDisplayText)
gridView1.Columns(0).ColumnEdit = editor
' add the second column bound to the same field for easier reference
gridView1.Columns.AddField("Number").VisibleIndex = 1
lookUpEdit1.Properties.Assign(editor)
lookUpEdit1.EditValue = 0
End Sub
Const NotFoundText As String = "???"
Private Sub RepositoryItemLookUpEdit_CustomDisplayText(ByVal sender As Object, ByVal e As CustomDisplayTextEventArgs)
Dim props As RepositoryItemLookUpEdit
If TypeOf sender Is LookUpEdit Then
props = TryCast(sender, LookUpEdit).Properties
Else
props = TryCast(sender, RepositoryItemLookUpEdit)
End If
If props IsNot Nothing AndAlso (TypeOf e.Value Is Integer) Then
Dim row As Object = props.GetDataSourceRowByKeyValue(e.Value)
If row Is Nothing Then
e.DisplayText = NotFoundText
End If
End If
End Sub
End Class
End Namespace