你有关于搜索引擎和排序的树视图的源代码吗? [英] did you have source code about tree view with search engine and sort

查看:62
本文介绍了你有关于搜索引擎和排序的树视图的源代码吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是情况。

项目是这样的(例如:http://demos.telerik.com/aspnet-ajax/dropdowntree/examples/functionality/filtering/defaultcs.aspx)

我需要的那个网站。使用窗口应用程序。



但我的问题是。他们是否连接到xml文件。 exe文件调用xml进行树视图。

有人可以帮助解决这个问题。请。我不擅长vb.net。仅在网络应用程序。



我重复我的要求:使用treeview搜索并按类别和字母顺序排序。然后当我点击文件时可以在treeview中打开文档和url。有人有这个问题。



谢谢。

jane

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

推荐答案

你好简,



我理解你的要求,但在这个特定的论坛上要求太多了。您需要帮助来构建功能,这很好。但是首先尝试自己构建一些东西,然后当你遇到困难时,问一个关于某个控件或控件行为的特定问题。



有很多好东西有关如何使用Treelists的示例。例如:



http://www.dotnetperls.com/treeview [ ^ ]

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



希望这有帮助。
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.


你好rick van。





i已经有了。但是,我的项目已经是exe文件。但他们根据我的资源调用或找到xml文件。因为我总是改变xml文件。用于打开文件,doc,exe,url等。



但我有bug。谢谢你的回复。对此,我真的非常感激。

但不是我想要的那样。

但是如果你有的话。其他内容。



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.

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





-----这是我的代码,但是他们没有打电话xml。他们叫司机d:有人这样......



----- this my code but they not call the xml. they call the driver d: some like this..


这篇关于你有关于搜索引擎和排序的树视图的源代码吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆