This repository has been archived by the owner on Sep 11, 2023. It is now read-only.
/
MyGridLookupDataSourceHelper.vb
59 lines (53 loc) · 2.3 KB
/
MyGridLookupDataSourceHelper.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
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms
Imports DevExpress.XtraEditors
Imports DevExpress.XtraGrid.Views.Grid
Imports System.Collections
Namespace WindowsApplication1
Public Class MyGridLookupDataSourceHelper
Private _MyObject As New MyObject()
Private _DataSourceWrapper As MyDataSourceWrapper
Private edit As GridLookUpEdit
Private popupOpened As Boolean = False
Public Sub New(ByVal edit As GridLookUpEdit, ByVal dataSource As ITypedList, ByVal displayMember As String, ByVal valueMember As String)
Me.edit = edit
_MyObject.ID = Int32.MinValue+5
_DataSourceWrapper = New MyDataSourceWrapper(dataSource, _MyObject, valueMember, displayMember)
edit.Properties.DisplayMember = displayMember
edit.Properties.ValueMember = valueMember
edit.Properties.DataSource = _DataSourceWrapper
AddHandler edit.Properties.View.CustomRowFilter, AddressOf View_CustomRowFilter
AddHandler edit.ProcessNewValue, AddressOf edit_ProcessNewValue
edit.Properties.View.RefreshData()
AddHandler edit.Properties.QueryPopUp, AddressOf Properties_QueryPopUp
End Sub
Private Sub Properties_QueryPopUp(ByVal sender As Object, ByVal e As CancelEventArgs)
Me.popupOpened = True
edit.Properties.View.DataController.DoRefresh()
End Sub
Public Shared Sub SetupGridLookUpEdit(ByVal edit As GridLookUpEdit, ByVal dataSource As ITypedList, ByVal displayMember As String, ByVal valueMember As String)
Dim TempMyGridLookupDataSourceHelper As MyGridLookupDataSourceHelper = New MyGridLookupDataSourceHelper(edit, dataSource, displayMember, valueMember)
End Sub
Private Sub View_CustomRowFilter(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Base.RowFilterEventArgs)
If (Not popupOpened) Then
Return
End If
If TypeOf _DataSourceWrapper(e.ListSourceRow) Is MyObject Then
e.Visible = False
e.Handled = True
End If
End Sub
Private Sub edit_ProcessNewValue(ByVal sender As Object, ByVal e As DevExpress.XtraEditors.Controls.ProcessNewValueEventArgs)
_MyObject.DisplayText = e.DisplayValue
Me.popupOpened = False
edit.Properties.View.DataController.DoRefresh()
e.Handled = True
End Sub
End Class
End Namespace