Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Treeview and regex

Treeview and regex

Scheduled Pinned Locked Moved Visual Basic
csharpdata-structuresregexquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    spaceus
    wrote on last edited by
    #1

    I'm new to vb.net and I was wondering if it would be possible to use regex on a treeview? I haven't got any code but at least that makes for a quick read.. what I would like is to be able to traverse a treeview for a regex, then building a new treeview with the nodes found maintaining the original structure of the tree (parent - child) inputs are extremely welcome peace How terrible is wisdom when it brings no profit to the wise

    L 1 Reply Last reply
    0
    • S spaceus

      I'm new to vb.net and I was wondering if it would be possible to use regex on a treeview? I haven't got any code but at least that makes for a quick read.. what I would like is to be able to traverse a treeview for a regex, then building a new treeview with the nodes found maintaining the original structure of the tree (parent - child) inputs are extremely welcome peace How terrible is wisdom when it brings no profit to the wise

      L Offline
      L Offline
      Lewis Moten
      wrote on last edited by
      #2

      In a nutshell ... Private Sub btnMatch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMatch.Click targetTree.Nodes.Clear() Dim Expression As New Regex(txtExpression.Text) Dim Matches As MatchCollection For Each node As TreeNode In sourceTree.Nodes If Expression.IsMatch(node.FullPath) Then targetTree.Nodes.Add(node.Clone) End If CheckNodes(Expression, node, targetTree) Next End Sub Private Sub CheckNodes(ByVal expression As Regex, ByVal node As TreeNode, ByVal target As TreeView) For Each child As TreeNode In node.Nodes If expression.IsMatch(child.FullPath) Then NodeParent(target, node).Nodes.Add(child.Clone) End If CheckNodes(expression, child, target) Next End Sub Private Function NodeParent(ByVal target As TreeView, ByVal node As TreeNode) As TreeNode If node.Parent Is Nothing Then For Each Parent As TreeNode In target.Nodes If Parent.Text = node.Text Then Return Parent Next Return target.Nodes.Add(node.Text) End If Return NodeParent(target, node.Parent).Nodes.Add(node.Text) End Function

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups