473,379 Members | 1,257 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,379 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 2034
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: http://www.dslextreme.com/users/kevinlyons/selectBoxes.html I am having difficulty getting the...
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, Gaby
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 shortcut menu to appear if the point of the right...
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 clicked. Currently you have to left click a node...
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 have looked at selectedNode, but I don't know how to...
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 = mytreenode.clone() gives the same error. The...
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 below. Details |__ policy status |__ created by...
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 side.) I have two DropDownList controls the...
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 nodes of that node in listview control 2. ...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.