Click here to Skip to main content
15,904,934 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
this is situation.
the project was like this (example:http://demos.telerik.com/aspnet-ajax/dropdowntree/examples/functionality/filtering/defaultcs.aspx)
that site that i need for. using window application.

but my problem was. are they connecting to xml file. the exe file was call the xml for a treeview.
someone can help about this problem. please. im not good at vb.net. only at web application.

i repeat my my requirement: search with treeview and sort by category and alphabetical. then when i click the file can open the document and url inside at treeview. someone have this problem.

thanks.
jane
Posted

Hi Jane,

I understand your request, however this is way too much to ask in this particular forum. You want help to build a functionality, that's fine. But try to build something yourself first, and then when you're stuck, ask a particular question about some control or behaviour of a control.

There are plenty of good example on how to work with Treelists. For example :

http://www.dotnetperls.com/treeview[^]
http://stackoverflow.com/questions/4912873/treeview-with-columns[^]

Hope this helps.
 
Share this answer
 
hello rick van.


i already have that. but, my project was exe file already. but they call or locate the xml file, base on my resources. cause i change always the xml file. for use to open file, doc, exe, url or etc.

and but i have bug. thanks your respond. i really appreciate it.
but not like that i needed.
but if you have. other content about that.

VB
Public Class Form1

    Private mRootPath As String = "D:\Templates dotx"

    Property RootPath() As String
        Get
            Return mRootPath
        End Get
        Set(ByVal value As String)
            mRootPath = value
        End Set
End Property


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        
        Call LoadList()
        TreeView1.ExpandAll()
    End Sub

    Sub LoadList()
        ' when our component is loaded, we initialize the TreeView by  adding  the root node
        Dim mRootNode As New TreeNode
        mRootNode.Text = RootPath
        mRootNode.Tag = RootPath
        mRootNode.Nodes.Add("*DUMMY*")


        TreeView1.Nodes.Add(mRootNode)
    End Sub

    Private Sub TreeView1_NodeMouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeNodeMouseClickEventArgs) Handles TreeView1.NodeMouseDoubleClick
        ' only proceed if the node represents a file
        If e.Node.ImageKey = "folder" Then Exit Sub
        If e.Node.Tag = "" Then Exit Sub
        ' try to open the file
        Try
            Process.Start(e.Node.Tag)
        Catch ex As Exception
            MessageBox.Show("Error opening file: " & ex.Message)
        End Try
    End Sub

    Private Sub TreeView1_BeforeCollapse(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewCancelEventArgs) Handles TreeView1.BeforeCollapse
        ' clear the node that is being collapsed
        e.Node.Nodes.Clear()
        ' add a dummy TreeNode to the node being collapsed so it is expandable
        e.Node.Nodes.Add("*DUMMY*")
    End Sub

    Private Sub TreeView1_BeforeExpand(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewCancelEventArgs) Handles TreeView1.BeforeExpand
        ' clear the expanding node so we can re-populate it, or else we end up with duplicate nodes
        e.Node.Nodes.Clear()
        ' get the directory representing this node

        Dim mNodeDirectory As IO.DirectoryInfo
        mNodeDirectory = New IO.DirectoryInfo(e.Node.Tag.ToString)
        ' add each subdirectory from the file system to the expanding node as a child node


        For Each mDirectory As IO.DirectoryInfo In mNodeDirectory.GetDirectories
            ' declare a child TreeNode for the next subdirectory

            Dim mDirectoryNode As New TreeNode
            ' store the full path to this directory in the child TreeNode's Tag property
            If mDirectory.Name = "Documents and Settings" Then
                GoTo here
            End If

            mDirectoryNode.Tag = mDirectory.FullName
            ' set the child TreeNodes's display text
            mDirectoryNode.Text = mDirectory.Name
            ' add a dummy TreeNode to this child TreeNode to make it expandable
            mDirectoryNode.Nodes.Add("*DUMMY*")
            ' add this child TreeNode to the expanding TreeNode
            e.Node.Nodes.Add(mDirectoryNode)

            mDirectoryNode.ImageKey = CacheShellIcon(mDirectory.FullName)
            mDirectoryNode.SelectedImageKey = mDirectoryNode.ImageKey
here:
        Next

        ' add each file from the file system that is a child of the argNode that was passed in
        For Each mFile As IO.FileInfo In mNodeDirectory.GetFiles
            If (Trim(TextBox1.Text)).Length > 0 Then
                ' declare a TreeNode for this file
                Dim mFileNode As New TreeNode
                ' store the full path to this file in the file TreeNode's Tag property
                If InStr(UCase(mFile.Name), UCase(Trim(TextBox1.Text))) Then
                    mFileNode.Tag = mFile.FullName
                    ' set the file TreeNodes's display text
                    mFileNode.Text = mFile.Name
                    mFileNode.ImageKey = CacheShellIcon(mFile.FullName)
                    mFileNode.SelectedImageKey = mFileNode.ImageKey & "-open"
                    ' add this file TreeNode to the TreeNode that is being populated
                    e.Node.Nodes.Add(mFileNode)
                End If

            Else
                ' declare a TreeNode for this file
                Dim mFileNode As New TreeNode
                ' store the full path to this file in the file TreeNode's Tag property
                mFileNode.Tag = mFile.FullName
                ' set the file TreeNodes's display text
                mFileNode.Text = mFile.Name
                mFileNode.ImageKey = CacheShellIcon(mFile.FullName)
                mFileNode.SelectedImageKey = mFileNode.ImageKey & "-open"
                ' add this file TreeNode to the TreeNode that is being populated
                e.Node.Nodes.Add(mFileNode)
            End If
        Next

    End Sub

    Public Declare Auto Function SHGetFileInfo Lib "shell32.dll" (ByVal pszPath As String, ByVal dwFileAttributes As Integer, ByRef psfi As SHFILEINFO, ByVal cbFileInfo As Integer, ByVal uFlags As Integer) As IntPtr

    Public Const SHGFI_ICON As Integer = &H100
    Public Const SHGFI_SMALLICON As Integer = &H1
    Public Const SHGFI_LARGEICON As Integer = &H0
    Public Const SHGFI_OPENICON As Integer = &H2

    Structure SHFILEINFO
        Public hIcon As IntPtr
        Public iIcon As Integer
        Public dwAttributes As Integer
        <runtime.interopservices.marshalas(runtime.interopservices.unmanagedtype.byvaltstr,> _
        Public szDisplayName As String
        <runtime.interopservices.marshalas(runtime.interopservices.unmanagedtype.byvaltstr,> _
        Public szTypeName As String
    End Structure

    ' GetShellIconAsImage
    Function GetShellIconAsImage(ByVal argPath As String) As Image
        Dim mShellFileInfo As New SHFILEINFO
        mShellFileInfo.szDisplayName = New String(Chr(0), 260)
        mShellFileInfo.szTypeName = New String(Chr(0), 80)
        SHGetFileInfo(argPath, 0, mShellFileInfo, System.Runtime.InteropServices.Marshal.SizeOf(mShellFileInfo), SHGFI_ICON Or SHGFI_SMALLICON)
        ' attempt to create a System.Drawing.Icon from the icon handle that was returned in the SHFILEINFO structure
        Dim mIcon As System.Drawing.Icon
        Dim mImage As System.Drawing.Image
        Try
            mIcon = System.Drawing.Icon.FromHandle(mShellFileInfo.hIcon)
            mImage = mIcon.ToBitmap
        Catch ex As Exception
            ' for some reason the icon could not be converted so create a blank System.Drawing.Image to return instead
            mImage = New System.Drawing.Bitmap(16, 16)
        End Try
        ' return the final System.Drawing.Image
        Return mImage
    End Function

    Function CacheShellIcon(ByVal argPath As String) As String
        Dim mKey As String = Nothing
        ' determine the icon key for the file/folder specified in argPath
        If IO.Directory.Exists(argPath) = True Then
            mKey = "folder"
        ElseIf IO.File.Exists(argPath) = True Then
            mKey = IO.Path.GetExtension(argPath)
        End If
        ' check if an icon for this key has already been added to the collection
        If ImageList1.Images.ContainsKey(mKey) = False Then
            ImageList1.Images.Add(mKey, GetShellIconAsImage(argPath))
        End If
        Return mKey
    End Function

    Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
        If e.KeyCode = Keys.Enter Then
            If Trim(TextBox1.Text).Length > 0 Then
                TreeView1.Nodes.Clear()
                Call LoadList()
                

                Call GetAllNodes()
                TreeView1.Sort()
                TreeView1.ExpandAll()
            Else
                TreeView1.Nodes.Clear()
                Call LoadList()
                TreeView1.Sort()
                TreeView1.ExpandAll()
            End If

        End If
        
    End Sub

    Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress

    End Sub


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


    End Sub

    Protected Function GetAllNodes() As List(Of TreeNode)

        Dim allNodes As List(Of TreeNode) = New List(Of TreeNode)()

        ' start recursion for each root node of the treeview
        For i As Integer = 0 To TreeView1.Nodes.Count - 1
            GetAllNodes(TreeView1.Nodes(i), allNodes)

        Next

        Return allNodes

    End Function

    Protected Sub GetAllNodes(ByVal subRoot As TreeNode, ByVal allNodes As List(Of TreeNode))

        ' check for null (this can be removed since within th
        If (subRoot Is Nothing) Then
            Exit Sub
        End If



        'ulitloop:

        ' add subroot
        allNodes.Add(subRoot)
        ' add all it's children
        For i As Integer = 0 To subRoot.Nodes.Count - 1
            GetAllNodes(subRoot.Nodes(i), allNodes)
            'MsgBox(subRoot.Nodes(i).Text)

            For Each aa In subRoot.Nodes(i).Nodes
                If InStr(UCase(aa.ToString), UCase(Trim(TextBox1.Text))) Then
                    ' MsgBox(aa.ToString)
                    'GoTo ulitloop
                End If
            Next
            


        Next


    End Sub

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

    End Sub

    Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect

    End Sub
End Class


----- this my code but they not call the xml. they call the driver d: some like this..
 
Share this answer
 
v2
Comments
janesanjuan 30-Sep-13 20:40pm    
hisome can help about to call the xml file.. like i said on my problem

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900