469,903 Members | 1,951 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,903 developers. It's quick & easy.

Search and select an item from treeview

How can I find and select an specific item in an treeview control?

I want to create a search feature on my treeview.

Thanks in advance,

Gaby
Nov 15 '05 #1
4 20178
You'll have to implement a SelectItem method yourself - and for that, you'll
probably have to recurse through all the nodes of the tree view and select
the one that matches your criteria.

-vJ

"G Uljee" <le***@xs4all.nl> wrote in message
news:3f*********************@news.xs4all.nl...
How can I find and select an specific item in an treeview control?

I want to create a search feature on my treeview.

Thanks in advance,

Gaby

Nov 15 '05 #2
I've already try that, see code.
My question now is how can I select the specific node?
private void bSearch_Click(object sender, System.EventArgs e)
{
TreeNode currentnode = new TreeNode();
try
{
foreach (TreeNode node in this.tvw.Nodes)
{
if (node.Text.Substring(0,this.tSearch.Text.Length).T oLower() ==
this.tSearch.Text.ToLower())
{
MessageBox.Show("2");
break;
}
else
foreach (TreeNode node1 in node.Nodes)
{
if (node1.Text.Substring(0,this.tSearch.Text.Length). ToLower() ==
this.tSearch.Text.ToLower())
{
MessageBox.Show("2");
break;
}
else
{
foreach (TreeNode node2 in node1.Nodes)
{
if (node2.Text.Substring(0,this.tSearch.Text.Length). ToLower() ==
this.tSearch.Text.ToLower())
{
currentnode = node2;
break;
}
}
}
}
}

Gaby

"Vijaye Raji" <no************@hotmail.com> wrote in message
news:eI**************@tk2msftngp13.phx.gbl...
You'll have to implement a SelectItem method yourself - and for that, you'll probably have to recurse through all the nodes of the tree view and select
the one that matches your criteria.

-vJ

"G Uljee" <le***@xs4all.nl> wrote in message
news:3f*********************@news.xs4all.nl...
How can I find and select an specific item in an treeview control?

I want to create a search feature on my treeview.

Thanks in advance,

Gaby


Nov 15 '05 #3
tvw.SelectedNode = node;

-vJ

"G Uljee" <le***@xs4all.nl> wrote in message
news:3f*********************@news.xs4all.nl...
I've already try that, see code.
My question now is how can I select the specific node?
private void bSearch_Click(object sender, System.EventArgs e)
{
TreeNode currentnode = new TreeNode();
try
{
foreach (TreeNode node in this.tvw.Nodes)
{
if (node.Text.Substring(0,this.tSearch.Text.Length).T oLower() ==
this.tSearch.Text.ToLower())
{
MessageBox.Show("2");
break;
}
else
foreach (TreeNode node1 in node.Nodes)
{
if (node1.Text.Substring(0,this.tSearch.Text.Length). ToLower() ==
this.tSearch.Text.ToLower())
{
MessageBox.Show("2");
break;
}
else
{
foreach (TreeNode node2 in node1.Nodes)
{
if (node2.Text.Substring(0,this.tSearch.Text.Length). ToLower() ==
this.tSearch.Text.ToLower())
{
currentnode = node2;
break;
}
}
}
}
}

Gaby

"Vijaye Raji" <no************@hotmail.com> wrote in message
news:eI**************@tk2msftngp13.phx.gbl...
You'll have to implement a SelectItem method yourself - and for that,

you'll
probably have to recurse through all the nodes of the tree view and select the one that matches your criteria.

-vJ

"G Uljee" <le***@xs4all.nl> wrote in message
news:3f*********************@news.xs4all.nl...
How can I find and select an specific item in an treeview control?

I want to create a search feature on my treeview.

Thanks in advance,

Gaby



Nov 15 '05 #4
tvw.SelectedNode = node2;

tvw.Select();

tvw.Focus();

that's the solution...

Cheers...

"Vijaye Raji" <no************@hotmail.com> wrote in message
news:uv**************@TK2MSFTNGP12.phx.gbl...
tvw.SelectedNode = node;

-vJ

"G Uljee" <le***@xs4all.nl> wrote in message
news:3f*********************@news.xs4all.nl...
I've already try that, see code.
My question now is how can I select the specific node?
private void bSearch_Click(object sender, System.EventArgs e)
{
TreeNode currentnode = new TreeNode();
try
{
foreach (TreeNode node in this.tvw.Nodes)
{
if (node.Text.Substring(0,this.tSearch.Text.Length).T oLower() ==
this.tSearch.Text.ToLower())
{
MessageBox.Show("2");
break;
}
else
foreach (TreeNode node1 in node.Nodes)
{
if (node1.Text.Substring(0,this.tSearch.Text.Length). ToLower() ==
this.tSearch.Text.ToLower())
{
MessageBox.Show("2");
break;
}
else
{
foreach (TreeNode node2 in node1.Nodes)
{
if (node2.Text.Substring(0,this.tSearch.Text.Length). ToLower() ==
this.tSearch.Text.ToLower())
{
currentnode = node2;
break;
}
}
}
}
}

Gaby

"Vijaye Raji" <no************@hotmail.com> wrote in message
news:eI**************@tk2msftngp13.phx.gbl...
You'll have to implement a SelectItem method yourself - and for that,

you'll
probably have to recurse through all the nodes of the tree view and select the one that matches your criteria.

-vJ

"G Uljee" <le***@xs4all.nl> wrote in message
news:3f*********************@news.xs4all.nl...
> How can I find and select an specific item in an treeview control?
>
> I want to create a search feature on my treeview.
>
> Thanks in advance,
>
>
>
> Gaby
>
>



Nov 15 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Polo | last post: by
1 post views Thread by Patrick | last post: by
13 posts views Thread by André Nogueira | last post: by
3 posts views Thread by Michael_Burgess | last post: by
5 posts views Thread by =?Utf-8?B?dmlubw==?= | last post: by
1 post views Thread by Waqarahmed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.