itangiang
/
implement-the-addnewnode-method-in-treelist-like-the-addnewrow-one-in-gridcontrol-e4190
Public
forked from DevExpress-Examples/out-of-maintenance-implement-the-addnewnode-method-in-treelist-like-the-addnewrow-one-in-gridcontrol
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyTreeList.vb
85 lines (65 loc) · 2.05 KB
/
MyTreeList.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
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Windows.Forms
Imports DevExpress.XtraTreeList
Imports DevExpress.XtraTreeList.Nodes
Imports System.ComponentModel
Namespace WindowsFormsApplication1
<System.ComponentModel.DesignerCategory("")> _
Public Class InitNewNodeEventArgs
Inherits EventArgs
Public Sub New(ByVal nodeId As Integer)
Me.nodeId_Renamed = nodeId
End Sub
Private nodeId_Renamed As Integer
Public ReadOnly Property NodeId() As Integer
Get
Return nodeId_Renamed
End Get
End Property
End Class
Public Class MyTreeList
Inherits TreeList
Public Delegate Sub InitNewRowEventHandler(ByVal sender As Object, ByVal a As InitNewNodeEventArgs)
Public Event InitNewNode As InitNewRowEventHandler
Private _NewAddedNode As TreeListNode
Public Sub New()
MyBase.New()
End Sub
Public Sub New(ByVal ignore As Object)
MyBase.New(ignore)
End Sub
Public Sub AddNewNode()
Dim Id As Integer = -1
_NewAddedNode = Me.AppendNode(Nothing, Id)
isNewRowDirty = False
Me.FocusedNode = _NewAddedNode
RaiseInitNewNode(New InitNewNodeEventArgs(_NewAddedNode.Id))
End Sub
Private isNewRowDirty As Boolean = False
Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
Dim info As TreeListHitInfo = Me.CalcHitInfo(e.Location)
If info.HitInfoType = HitInfoType.Cell Then
isNewRowDirty = True
Me.RefreshNode(_NewAddedNode)
End If
MyBase.OnMouseDown(e)
End Sub
Protected Overrides Sub RaiseCustomDrawNodeIndicator(ByVal e As CustomDrawNodeIndicatorEventArgs)
If e.Node IsNot _NewAddedNode OrElse isNewRowDirty Then
MyBase.RaiseCustomDrawNodeIndicator(e)
Return
End If
e.ImageIndex = 1
e.Painter.DrawObject(e.ObjectArgs)
End Sub
Protected Overridable Sub RaiseInitNewNode(ByVal e As InitNewNodeEventArgs)
RaiseEvent InitNewNode (Me,e)
End Sub
Public Function IsNewNode(ByVal nodeId As Integer) As Boolean
Return nodeId = _NewAddedNode.Id
End Function
End Class
End Namespace