VB.Net Transfer TreeView Nodes To DataGridView

How To Set TreeView Nodes Values Into DataGridView Rows Using Visual Basic .Net

Transfer TreeView Nodes To DataGridView Using VB.Net

In this VB.NET Tutorial we will see How To Get TreeView Nodes Data And Set It Into DataGridView Rows Using For Loop On Button Click Event In Visual Basic.Net  Programming Language And Visual  Studio Editor.




Project Source Code:


Public Class TreeView_To_Datagridview

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        ' go through all nodes
        For i As Integer = 0 To TreeView1.Nodes.Count - 1 Step +1

            ' create a new node
            Dim node As New TreeNode()

            ' set the created node equal to the current one
            node = TreeView1.Nodes(i)
           
            ' create a row
            Dim row(node.Nodes.Count) As Object

            ' add values from node to the row
            For j As Integer = 0 To node.Nodes.Count - 1 Step +1

                row(j) = node.Nodes(j).Text

            Next j
            
            ' add row to the datagridview
            DataGridView1.Rows.Add(row)

        Next i

    End Sub
End Class


OutPut:

TreeView To DataGridView In VB.Net




Share this

Related Posts

Previous
Next Post »