472,328 Members | 1,716 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Select correct treenode with first click

Hi, does anyone know how to select a treenode with the first click? the
first click on a treeview will highlight the node under the mouse when it
was clicked BUT that node isn't actually selected until you click on it
again - very annoying property. i know i have to handle an event to set the
selected node to be the highlighted node but i have no idea how.

Thanks for any help,

Matt
Nov 23 '05 #1
3 1971
try using the MousDown or MouseUp event, whichever proves more reliable.
e.g.:
private void treeView1_MouseDown(object sender, MouseEventArgs e)
{
try
{
TreeNode node =
this.treeView1.GetNodeAt(PointToClient(Cursor.Posi tion));
this._curSelectedNode = node;
}
catch
{}
}
// _curSelectedNode is just a class-level field to hold the selection
--Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Matthew Woods" wrote:
Hi, does anyone know how to select a treenode with the first click? the
first click on a treeview will highlight the node under the mouse when it
was clicked BUT that node isn't actually selected until you click on it
again - very annoying property. i know i have to handle an event to set the
selected node to be the highlighted node but i have no idea how.

Thanks for any help,

Matt

Nov 23 '05 #2
Thanks for your help but it doesn't work. My code is as follows:

1 private void tvServerProducts_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)
2 {
3 try
4 {
5 TreeNode tn =
tvServerProducts.GetNodeAt(PointToClient(Cursor.Po sition));
6 tvServerProducts.SelectedNode = tn;
7 }
8 catch {}
9 }

but if i put a breakpoint at line 6 then it tells me tn is undefined. the
same thing happens in the MouseUp event.

"Peter Bromberg [C# MVP]" <pb*******@yahoo.nospammin.com> wrote in message
news:73**********************************@microsof t.com...
try using the MousDown or MouseUp event, whichever proves more reliable.
e.g.:
private void treeView1_MouseDown(object sender, MouseEventArgs e)
{
try
{
TreeNode node =
this.treeView1.GetNodeAt(PointToClient(Cursor.Posi tion));
this._curSelectedNode = node;
}
catch
{}
}
// _curSelectedNode is just a class-level field to hold the selection
--Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Matthew Woods" wrote:
Hi, does anyone know how to select a treenode with the first click? the
first click on a treeview will highlight the node under the mouse when it was clicked BUT that node isn't actually selected until you click on it
again - very annoying property. i know i have to handle an event to set the selected node to be the highlighted node but i have no idea how.

Thanks for any help,

Matt

Nov 23 '05 #3
Ok, it does work, but only if you click on the node line or the image. if
you click on the text then it doesn't return any node.

"Peter Bromberg [C# MVP]" <pb*******@yahoo.nospammin.com> wrote in message
news:73**********************************@microsof t.com...
try using the MousDown or MouseUp event, whichever proves more reliable.
e.g.:
private void treeView1_MouseDown(object sender, MouseEventArgs e)
{
try
{
TreeNode node =
this.treeView1.GetNodeAt(PointToClient(Cursor.Posi tion));
this._curSelectedNode = node;
}
catch
{}
}
// _curSelectedNode is just a class-level field to hold the selection
--Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Matthew Woods" wrote:
Hi, does anyone know how to select a treenode with the first click? the
first click on a treeview will highlight the node under the mouse when it was clicked BUT that node isn't actually selected until you click on it
again - very annoying property. i know i have to handle an event to set the selected node to be the highlighted node but i have no idea how.

Thanks for any help,

Matt

Nov 23 '05 #4

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

Similar topics

12
by: Kevin Lyons | last post by:
Hello, I am trying to get my select options (courses) passed correctly from the following URL: ...
4
by: G Uljee | last post by:
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, ...
2
by: Sean | last post by:
Hi, I have a treeview and user can right click the treenodes, depending on the nodes, different shortcut menu will appear. I want only the...
2
by: paradox | last post by:
How can I go about having a TreeNode selected when I right click? I tried using the Click event, but the event does not pass in the node that was...
2
by: Wes | last post by:
I have a treeview that I am continually added nodes to. Each time a new node is added I would like to select that node. Is this possible? I...
2
by: bclegg | last post by:
Hi, When I implement the example code it errors with 'No parameterless constructor defined for this object.' experimenting with dim o as object...
4
by: praveen | last post by:
I have a form with treeview control loaded from xml document,text box, two buttons named "Find" and "FindNext" and my treeview which looks like...
3
by: Lohboy | last post by:
Using ASP.NET and IE7. (Sorry if I am posting in the wrong forum but my problem seemed to be more related to the JavaScript side than the ASP.NET...
0
by: divya1949 | last post by:
Create a windows c# application which will Read a xml file and populate nodes in the treeview. 1 On selection of treenode display the child...
0
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

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.