How did you add the TreeNodes in the first place?
Wyck in the top of the class the method addmore:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Text.RegularExpressions;
namespace ScrollLabelTest
{
public partial class DisplayResponses : Form
{
private List<string> nodesNames = new List<string>();
private List<TreeNode> CurrentNodeMatches = new List<TreeNode>();
public DisplayResponses()
{
InitializeComponent();
addmore();
}
public void addmore()
{
foreach (List<string> l_branch in ListsExtractions.responsers)
{
TreeNode l_node = treeView1.Nodes.Add(l_branch[l_branch.Count - 1]);
for (int l_count = 0; l_count < l_branch.Count - 1; l_count++)
{
l_node.Nodes.Add(l_branch[l_count]);
}
}
}
private void DisplayResponses_Load(object sender, EventArgs e)
{
}
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
try
{
txtName.Text = "";
txtParentName.Text = "";
txtText.Text = "";
txtTag.Text = "";
if (treeView1.SelectedNode.Name != null)
{
txtName.Text = treeView1.SelectedNode.Name.ToString();
}
if (treeView1.SelectedNode.Text != null)
{
txtText.Text = treeView1.SelectedNode.Text.ToString();
}
if (treeView1.SelectedNode.Tag != null)
{
txtTag.Text = treeView1.SelectedNode.Tag.ToString();
}
if (treeView1.SelectedNode.Parent != null)
{
txtParentName.Text = treeView1.SelectedNode.Parent.Text.ToString();
}
}
catch { }
}
private void treeView1_Click(object sender, EventArgs e)
{
ClearBackColor();
}
private void button1_Click(object sender, EventArgs e)
{
ClearBackColor();
try
{
TreeNode[] tn = treeView1.Nodes[0].Nodes.Find(txtNodeSearch.Text, true);
for (int i = 0; i < tn.Length; i++)
{
treeView1.SelectedNode = tn[i];
treeView1.SelectedNode.BackColor = Color.Yellow;
}
}
catch { }
}
private void ClearBackColor()
{
TreeNodeCollection nodes = treeView1.Nodes;
foreach (TreeNode n in nodes)
{
ClearRecursive(n);
}
}
private void ClearRecursive(TreeNode treeNode)
{
foreach (TreeNode tn in treeNode.Nodes)
{
tn.BackColor = Color.White;
ClearRecursive(tn);
}
}
private void button2_Click(object sender, EventArgs e)
{
ClearBackColor();
FindByText();
treeView1.Invalidate();
}
private void FindByText()
{
TreeNodeCollection nodes = treeView1.Nodes;
foreach (TreeNode n in nodes)
{
FindRecursive(n);
}
}
private void FindRecursive(TreeNode treeNode)
{
foreach (TreeNode tn in treeNode.Nodes)
{
string result = Regex.Replace(tn.Text, @"^\d*\.\s*", string.Empty);
if (tn.Text == this.txtNodeTextSearch.Text)
tn.BackColor = Color.Yellow;
FindRecursive(tn);
}
}
private void button3_Click(object sender, EventArgs e)
{
ClearBackColor();
FindByTag();
}
private void FindByTag()
{
TreeNodeCollection nodes = treeView1.Nodes;
foreach (TreeNode n in nodes)
{
FindRecursiveTag(n);
}
}
private void FindRecursiveTag(TreeNode treeNode)
{
foreach (TreeNode tn in treeNode.Nodes)
{
if (tn.Tag.ToString() == this.txtTagSearch.Text)
tn.BackColor = Color.Yellow;
FindRecursiveTag(tn);
}
}
private void treeView1_DrawNode(object sender, DrawTreeNodeEventArgs e)
{
string texts = txtNodeTextSearch.Text;
if (txtNodeTextSearch.Text != "")
{
using (Font font = new Font(this.Font, FontStyle.Regular))
{
using (Brush brush = new SolidBrush(Color.Red))
{
e.Graphics.DrawString(texts, font, brush, e.Bounds.Left, e.Bounds.Top);
}
using (Brush brush = new SolidBrush(Color.Blue))
{
SizeF s = e.Graphics.MeasureString(texts, font);
e.Graphics.DrawString(texts, font, brush, e.Bounds.Left + (int)s.Width, e.Bounds.Top);
}
}
}
}
}
}
This method:
public void addmore()
{
foreach (List<string> l_branch in ListsExtractions.responsers)
{
TreeNode l_node = treeView1.Nodes.Add(l_branch[l_branch.Count - 1]);
for (int l_count = 0; l_count < l_branch.Count - 1; l_count++)
{
l_node.Nodes.Add(l_branch[l_count]);
}
}
}
This method build the first screenshot i uploaded here .
It's creating all the TreeNodes.
responsers is List<List<string>> type
I'm waiting for the List responsers to be created and then i click in form1 on strip menu and that make an instance for the class DisplayResponses and addmore create the TreeNodes.
No comments:
Post a Comment