-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form1.vb
88 lines (75 loc) · 2.78 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 System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms
Imports DevExpress.XtraGrid.Views.Grid
Imports DevExpress.XtraGrid.Views.Grid.ViewInfo
Imports DevExpress.XtraGrid
Imports DevExpress.XtraEditors.ViewInfo
Imports DevExpress.XtraGrid.Views.Grid.Drawing
Imports DevExpress.XtraEditors.DXErrorProvider
Imports DevExpress.XtraEditors.Drawing
Imports DevExpress.XtraGrid.Columns
Namespace WindowsApplication767
Partial Public Class Form1
Inherits Form
Private Function CreateTable(ByVal RowCount As Integer) As DataTable
Dim tbl As New DataTable()
tbl.Columns.Add("Name", GetType(String))
tbl.Columns.Add("Date", GetType(Date))
For i As Integer = 0 To RowCount - 1
tbl.Rows.Add(New Object() { String.Format("Name{0}", i), Date.Now.AddDays(i) })
Next i
Return tbl
End Function
Public Sub New()
InitializeComponent()
gridControl1.DataSource = CreateTable(20)
End Sub
Public Function GetError(ByVal value As Object, ByVal rowHandle As Integer, ByVal column As GridColumn) As String
If value Is Nothing Then
Return "value is null"
End If
If Not(TypeOf value Is Integer) Then
Return String.Empty
End If
If CInt(Fix(value)) Mod 2 = 0 Then
Return "value is even"
End If
If CInt(Fix(value)) < 10 Then
Return "value < 10"
End If
Return String.Empty
End Function
Private Sub SetError(ByVal cellInfo As BaseEditViewInfo, ByVal errorIconText As String)
If errorIconText = String.Empty Then
Return
End If
cellInfo.ErrorIconText = errorIconText
cellInfo.ShowErrorIcon = True
cellInfo.FillBackground = True
cellInfo.ErrorIcon = DXErrorProvider.GetErrorIconInternal(ErrorType.Critical)
End Sub
Private Sub gridView1_CustomDrawCell(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs) Handles gridView1.CustomDrawCell
Dim info As BaseEditViewInfo = CType(e.Cell, GridCellInfo).ViewInfo
Dim [error] As String = GetError(e.CellValue, e.RowHandle, e.Column)
SetError(info, [error])
info.CalcViewInfo(e.Cache.Graphics)
End Sub
Private Sub gridView1_CustomUnboundColumnData(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs) Handles gridView1.CustomUnboundColumnData
If e.IsGetData Then
e.Value = e.ListSourceRowIndex
End If
End Sub
Private Sub gridView1_ShownEditor(ByVal sender As Object, ByVal e As EventArgs) Handles gridView1.ShownEditor
Dim [error] As String = GetError(gridView1.GetFocusedValue(), gridView1.FocusedRowHandle, gridView1.FocusedColumn)
If [error] = String.Empty Then
Return
End If
gridView1.SetColumnError(gridView1.FocusedColumn, [error])
End Sub
End Class
End Namespace