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