| |

VerySource

 Forgot password?
 Register
Search
View: 917|Reply: 3

Please enlighten me, learn treeview and listview

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-11 14:00:01
| Show all posts |Read mode
Experts ask. I am newbie. I want to use treeview and listview to display the data in the database. Please master finger. The left side of the interface is treeview, and the right side is listview. treeview supports right mouse button operations, such as "add", "delete", etc. Click on the sub-items in the treeview, the corresponding specific content is displayed in the listview.
  Please experts can give a detailed code. Be grateful!
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-23 17:45:02
| Show all posts
top!
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-23 18:00:01
| Show all posts
up
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-23 18:30:01
| Show all posts
Is this ok?

How to use TreeView

Private Sub TreeView1_AfterCheck(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterCheck
        If e.Node.Checked = True Then
            'Process the parent node
            If Not e.Node.Parent Is Nothing Then
                e.Node.Parent.Checked = e.Node.Checked
            End If
        Else
            'Processing child nodes
            For Each Node As TreeNode In e.Node.Nodes
                If Not Node Is Nothing Then
                    Node.Checked = e.Node.Checked
                End If
            Next
        End If
        TreeView1.ExpandAll()
    End Sub



Read the value of treeview
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim i As Integer
        For i = 0 To TreeView1.Nodes.Count-1
            RichTextBox1.Text = RichTextBox1.Text + TreeView1.Nodes(i).Text + Chr(13)
            RichTextBox1.Text = RichTextBox1.Text + GetChildText(TreeView1.Nodes(i)) + Chr(13)
            RichTextBox1.Text = RichTextBox1.Text + Chr(13)
        Next i
    End Sub

    Private Function GetChildText(ByVal node As TreeNode) As String
        Dim sb As New System.Text.StringBuilder()
        Dim child As TreeNode
        For Each child In node.Nodes
            sb.Append(child.Text) sb.Append(Chr(9)).Append(child.Level).Append(Chr(9)).Append(child.FullPath.ToString).Append(Chr(9)). Append(Chr(13))
            sb.Append(GetChildText(child))
        Next child
        Return sb.ToString()
End Function


Add data to treeview
  Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        Dim SqlAdp1 As SqlDataAdapter

        Dim SqlCommString As String

        SqlCommString = "select * from sSystemMenu "

        SqlAdp1 = New SqlDataAdapter(SqlCommString, ConnectionString)

        Dim Dataset1 As New DataSet

        SqlAdp1.Fill(Dataset1, "sSystemMenu")


        TreeView1.Nodes.Clear()

        CreateTreeNode(TreeView1.Nodes, "0\", Dataset1.Tables(0))

        TreeView1.ExpandAll()
    End Sub

    Private Sub CreateTreeNode(ByVal nodes As TreeNodeCollection, ByVal parentid As String, ByVal dt As DataTable)
        Dim tmp As String = "[MenuParentCode]='"&parentid&"'"
        Dim rows() As DataRow = dt.Select(tmp)
        If rows.Length> 0 Then
            For i As Integer = 0 To rows.Length-1
                Dim node As New System.Windows.Forms.TreeNode
                node.Tag = rows(i)
                node.Text = Trim(rows(i).Item("Name")) + "[" + Trim(rows(i).Item("MenuCode")) + "]"
                node.SelectedImageIndex = rows(i).Item("SelectPic")
                node.ImageIndex = rows(i).Item("Pic")
                node.Tag = Trim(rows(i).Item("MenuCode"))
                nodes.Add(node)
                CreateTreeNode(node.Nodes, rows(i).Item("MenuPathCode"), dt)'Recursive call
            Next
        End If
    End Sub
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list