PDA

View Full Version : انتخاب ایتم ها در Tree View به وسیله کد نویسی



Purya Fallah
یک شنبه 22 اردیبهشت 1392, 01:05 صبح
سلام دوستان .
من یه کنترل Tree View دارم توی برنامم میخوام بدون دخالت کاربر Item ها رو انتخاب کنم . مثلا انتخاب آیتم قبلی یا انتخاب آیتم بعدی . اگه میشه راهنمایی کنید .

Purya Fallah
یک شنبه 22 اردیبهشت 1392, 18:32 عصر
کسی نیست کمک کنه ؟ :متعجب:

pooya1072
یک شنبه 22 اردیبهشت 1392, 18:50 عصر
سلام
با فرض اینکه یک treeview با نام tv_MainForm داری :
این برای پیشروی :

Dim tn As TreeNode = tv_MainForm.SelectedNode
If tn.FirstNode IsNot Nothing Then
tv_MainForm.SelectedNode = tn.FirstNode
Else
If tn.NextNode IsNot Nothing Then
tv_MainForm.SelectedNode = tn.NextNode
Else
While tn.Parent IsNot Nothing
If tn.Parent.NextNode IsNot Nothing Then
tv_MainForm.SelectedNode = tn.Parent.NextNode
Exit While
Else
tn = tn.Parent
End If
End While
End If
End If

اینم برای برگشت :

Dim tn As TreeNode = tv_MainForm.SelectedNode
If tn.PrevNode IsNot Nothing Then
tn = tn.PrevNode
If tn.LastNode IsNot Nothing Then
While tn.LastNode IsNot Nothing
If tn.LastNode.LastNode IsNot Nothing Then
tn = tn.LastNode.LastNode
Else
tv_MainForm.SelectedNode = tn.LastNode
Exit While
End If
tv_MainForm.SelectedNode = tn
End While
Else
tv_MainForm.SelectedNode = tn
End If
Else
If tn.Parent IsNot Nothing Then
tv_MainForm.SelectedNode = tn.Parent
Else
tv_MainForm.Focus()
Exit Sub
End If
End If