473,395 Members | 1,977 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to build function GetNodeByText for TreeView?

I have such one written in VB6.

Public Function GetNodeByText(colNodes As Nodes, sText As String) As Node
Dim nodEach As Node, nodResult As Node
For Each nodEach In colNodes
If nodEach.Text = sText Then
Set GetNodeByText = nodEach
Exit Function
End If
Next
End Function

But how to write in C# for .NET TreeView where each node has its own
collection of nodes and there is no total collection? It's rather difficult,
isn't it?
May someone help?

Thanks in advance.
Nov 17 '05 #1
1 1606
You could use a function recursively. Something like:

public class NodeGetter
{
TreeNode node;

public void GetNodeByText(TreeNodeCollection nodes, string text)
{
foreach (TreeNode node in nodes)
{
if (node.Text == text)
{
this.node = node;
break;
}
if (node.Nodes.Count > 0)
GetNodeByText(node.Nodes)
}
}

public static Main()
{
NodeGetter ng = new(NodeGetter);
ng.node = null;
TreeView tv = new TreeView();
// populate tree
ng.GetNodeByText(tv.Nodes,"sometext");
if (ng.node != null)
{
// do work with ng.node
}
}
}

"Ivan Abramov" <Iv*********@discussions.microsoft.com> wrote in message
news:1D**********************************@microsof t.com...
I have such one written in VB6.

Public Function GetNodeByText(colNodes As Nodes, sText As String) As Node
Dim nodEach As Node, nodResult As Node
For Each nodEach In colNodes
If nodEach.Text = sText Then
Set GetNodeByText = nodEach
Exit Function
End If
Next
End Function

But how to write in C# for .NET TreeView where each node has its own
collection of nodes and there is no total collection? It's rather
difficult,
isn't it?
May someone help?

Thanks in advance.

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: vijay | last post by:
hi, This is vijay kumar.p. Iam facing a problem regarding the treeview control. I am able to create a structure of the tree using the Node property from property pane, but how to build a...
10
by: dwok | last post by:
Does anyone know of a good article that discusses creating a "Tree View" control in ASP.NET? Or perhaps a Tree View Control that comes with source code? I have come across a lot of tree controls...
2
by: hibaru | last post by:
Hi Is it possible to call a javascript function from a treeview controls OnSelectedNodeChanged event? Something similar to a OnClientClick event for buttons? I cant seem to find anyway to do...
0
by: uncensored | last post by:
Hi, Sort of new with the whole treeview control and I was wondering is there a way to build a treeview menu using my SQL data I pull from a database instead of having to hard code it into the...
2
by: Ron M. Newman | last post by:
Hi, Just need a little advice. Id like to build *dynamic* context menus for tree nodes. I'm pretty versed in building context menus and attaching them to tree nodes. My question is, what...
2
by: hardieca | last post by:
Hi, I'm building a CMS and I'm banging my head against the wall over one part of the user interface. I have a Section entity which maybe have 0 or 1 parent Sections. So, as an example, I...
3
by: bg_ie | last post by:
Hi, Lets say I have a TreeView with nodes that represent objects of a number of different types. Is there a way of associating the Set method of each object with its node in the TreeView? That...
3
by: haakern | last post by:
Hi, In an aspx page, I've got a TreeView and a detail form and a print button. When the user clicks on the print button, I'd like to collapse the TreeView and send the page to the printer....
0
petepell
by: petepell | last post by:
Hello all, I am developing an application in VB 2008 that works with a SQL2005 DB to store and manipulate employee data. In one section of the app I want to be able to show a treeview of the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.