求节点拖动时的有效性检查,思路和代码都行。只有30分了,不好意思。

防止把父关系节点拖放到子节点上。
我想用Node.FullPath.Split("")来判定,可是发现有同名的节点就错了,如果循环树又觉得效力上有问题,那位大大有好的思路和代码请分享一下,谢谢。麻烦帮顶一下。。。谢谢。
---------------------------------------------------------------

问题解决了,也许其他大大有更好的方法。其中有些东东是为了测试用的,我就不删了。代码如下:
Public Class Form1
Inherits System.Windows.Forms.Form
Private nodeParent(0) As TreeNode
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
Private components As System.ComponentModel.IContainer
Friend WithEvents tre_File As System.Windows.Forms.TreeView
Friend WithEvents RichTextBox1 As System.Windows.Forms.RichTextBox
Friend WithEvents RichTextBox2 As System.Windows.Forms.RichTextBox
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox

 1<system.diagnostics.debuggerstepthrough()> Private Sub InitializeComponent()   
 2Me.tre_File = New System.Windows.Forms.TreeView   
 3Me.RichTextBox1 = New System.Windows.Forms.RichTextBox   
 4Me.RichTextBox2 = New System.Windows.Forms.RichTextBox   
 5Me.Label1 = New System.Windows.Forms.Label   
 6Me.Label2 = New System.Windows.Forms.Label   
 7Me.Button1 = New System.Windows.Forms.Button   
 8Me.TextBox1 = New System.Windows.Forms.TextBox   
 9Me.SuspendLayout()   
10Me.tre_File.AllowDrop = True   
11Me.tre_File.BackColor = System.Drawing.SystemColors.Window   
12Me.tre_File.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))   
13Me.tre_File.HideSelection = False   
14Me.tre_File.ImageIndex = -1   
15Me.tre_File.Location = New System.Drawing.Point(8, 8)   
16Me.tre_File.Name = "tre_File"   
17Me.tre_File.SelectedImageIndex = -1   
18Me.tre_File.Size = New System.Drawing.Size(696, 280)   
19Me.tre_File.TabIndex = 0   
20Me.RichTextBox1.Location = New System.Drawing.Point(8, 328)   
21Me.RichTextBox1.Name = "RichTextBox1"   
22Me.RichTextBox1.Size = New System.Drawing.Size(344, 200)   
23Me.RichTextBox1.TabIndex = 1   
24Me.RichTextBox1.Text = ""   
25Me.RichTextBox2.Location = New System.Drawing.Point(360, 328)   
26Me.RichTextBox2.Name = "RichTextBox2"   
27Me.RichTextBox2.Size = New System.Drawing.Size(344, 200)   
28Me.RichTextBox2.TabIndex = 2   
29Me.RichTextBox2.Text = ""   
30Me.Label1.AutoSize = True   
31Me.Label1.Location = New System.Drawing.Point(16, 304)   
32Me.Label1.Name = "Label1"   
33Me.Label1.Size = New System.Drawing.Size(54, 16)   
34Me.Label1.TabIndex = 3   
35Me.Label1.Text = "目标节点"   
36Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter   
37Me.Label2.AutoSize = True   
38Me.Label2.Location = New System.Drawing.Point(648, 304)   
39Me.Label2.Name = "Label2"   
40Me.Label2.Size = New System.Drawing.Size(54, 16)   
41Me.Label2.TabIndex = 4   
42Me.Label2.Text = "拖动节点"   
43Me.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter   
44Me.Button1.FlatStyle = System.Windows.Forms.FlatStyle.System   
45Me.Button1.Location = New System.Drawing.Point(72, 296)   
46Me.Button1.Name = "Button1"   
47Me.Button1.Size = New System.Drawing.Size(272, 23)   
48Me.Button1.TabIndex = 5   
49Me.Button1.Text = "ClearRichTextBox"   
50Me.TextBox1.Location = New System.Drawing.Point(360, 296)   
51Me.TextBox1.Name = "TextBox1"   
52Me.TextBox1.Size = New System.Drawing.Size(272, 20)   
53Me.TextBox1.TabIndex = 6   
54Me.TextBox1.Text = "TextBox1"   
55Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)   
56Me.ClientSize = New System.Drawing.Size(712, 534)   
57Me.Controls.Add(Me.TextBox1)   
58Me.Controls.Add(Me.Button1)   
59Me.Controls.Add(Me.Label2)   
60Me.Controls.Add(Me.Label1)   
61Me.Controls.Add(Me.RichTextBox2)   
62Me.Controls.Add(Me.RichTextBox1)   
63Me.Controls.Add(Me.tre_File)   
64Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow   
65Me.MaximizeBox = False   
66Me.MinimizeBox = False   
67Me.Name = "Form1"   
68Me.StartPosition = System.Windows.Forms.FormStartPosition.Manual   
69Me.Text = "Form1"   
70Me.ResumeLayout(False)   
71End Sub   
72#End Region</system.diagnostics.debuggerstepthrough()>
Published At
Categories with Web编程
Tagged with
comments powered by Disqus