Donate

Find Checked Treenode In TreeView Control Using LINQ In VB.NET

Here's one way of searching through a treenode using LINQ. Assuming that the search criteria is a List or array object.
 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
Public Class Form1
    Public Shared mat As List(Of String) = Nothing
 
    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
 
        mat = New List(Of String)
 
        mat.Add("Books")
        mat.Add("VB")
        mat.Add("Drinks")
        mat.Add("Food")
        mat.Add("Tea")
        mat.Add("Chod")
       
    End Sub
 
    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        If Not (mat Is Nothing) Then
            For Each tn As String In mat
                If (tvMat.Nodes.Find(tn, True).FirstOrDefault() IsNot Nothing) Then
                    If (tvMat.Nodes.Find(tn, True).FirstOrDefault().Checked) Then
                        MessageBox.Show(String.Format("Node Found"))
                        Me.Close()
                    End If
                End If
            Next
        End If
    End Sub
End Class

Comments

Donate

Popular Posts From This Blog

WPF CRUD Application Using DataGrid, MVVM Pattern, Entity Framework, And C#.NET

TypeScript Error Or Bug: The term 'tsc' is not recognized as the name of a cmdlet, function, script file, or operable program.

Invalid nested tag div found, expected closing tag input