473,413 Members | 2,051 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,413 software developers and data experts.

TreeView.GetNodeAt problem

I have a dragdrop event to capture the treenode that trigger that event.
However, I always get the returned node is null.

private void trvEmployee_DragDrop(object sender, DragEventArgs e)

{
TreeNode targetNode;

MessageBox.Show(e.X.ToString + " -- " + e.Y.ToString());
targetNode = trvEmployee.GetNodeAt(e.X, e.Y);
if (targetNode == null)
{ MessageBox.Show(" null");
}
else
{ MessageBox.Show(target.Text);
}
}

I don't know why it showed the e.X and e.Y have valid values but the
targetNode is null.

However, if I hardcode the
targetNode = trvEmployee.GetNodeAt(e.X, e.Y);
to e.X and e.Y to some value, it showed the node.
Note, the AllowDrop perperty has been set to true already.

Aug 15 '06 #1
4 5235
When you receive your coordinates, they're actually with respect to the
screen. For you treeview to understand you need to change them to the
"client" equvalent.

Point newPoint = treeView1.PointToClient( new Point(e.X, e.Y));

MessageBox.Show(e.X.ToString() + " -- " + e.Y.ToString());

targetNode = treeView1.GetNodeAt(newPoint.X, newPoint.Y);

if (targetNode == null)

Mike

http://www.seeknsnatch.com

"Alan T" <al*************@yahoo.com.auwrote in message
news:e0**************@TK2MSFTNGP04.phx.gbl...
>I have a dragdrop event to capture the treenode that trigger that event.
However, I always get the returned node is null.

private void trvEmployee_DragDrop(object sender, DragEventArgs e)

{
TreeNode targetNode;

MessageBox.Show(e.X.ToString + " -- " + e.Y.ToString());
targetNode = trvEmployee.GetNodeAt(e.X, e.Y);
if (targetNode == null)
{ MessageBox.Show(" null");
}
else
{ MessageBox.Show(target.Text);
}
}

I don't know why it showed the e.X and e.Y have valid values but the
targetNode is null.

However, if I hardcode the
targetNode = trvEmployee.GetNodeAt(e.X, e.Y);
to e.X and e.Y to some value, it showed the node.
Note, the AllowDrop perperty has been set to true already.

Aug 15 '06 #2
Hi thanks.
I tried using one statement:
targetNode = treeView1.GetNodeAt(newPoint(e.X, e.Y));

Is there any differences from yours ?
"Michael" <in**@seeknsnatch.comwrote in message
news:44***********************@news.free.fr...
When you receive your coordinates, they're actually with respect to the
screen. For you treeview to understand you need to change them to the
"client" equvalent.

Point newPoint = treeView1.PointToClient( new Point(e.X, e.Y));

MessageBox.Show(e.X.ToString() + " -- " + e.Y.ToString());

targetNode = treeView1.GetNodeAt(newPoint.X, newPoint.Y);

if (targetNode == null)

Mike

http://www.seeknsnatch.com

"Alan T" <al*************@yahoo.com.auwrote in message
news:e0**************@TK2MSFTNGP04.phx.gbl...
>>I have a dragdrop event to capture the treenode that trigger that event.
However, I always get the returned node is null.

private void trvEmployee_DragDrop(object sender, DragEventArgs e)

{
TreeNode targetNode;

MessageBox.Show(e.X.ToString + " -- " + e.Y.ToString());
targetNode = trvEmployee.GetNodeAt(e.X, e.Y);
if (targetNode == null)
{ MessageBox.Show(" null");
}
else
{ MessageBox.Show(target.Text);
}
}

I don't know why it showed the e.X and e.Y have valid values but the
targetNode is null.

However, if I hardcode the
targetNode = trvEmployee.GetNodeAt(e.X, e.Y);
to e.X and e.Y to some value, it showed the node.
Note, the AllowDrop perperty has been set to true already.


Aug 15 '06 #3
yeah, you need this

Point newPoint = treeView1.PointToClient( new Point(e.X, e.Y));

Mike
http://www.seeknsnatch.com

"Alan T" <al*************@yahoo.com.auwrote in message
news:um**************@TK2MSFTNGP06.phx.gbl...
Hi thanks.
I tried using one statement:
targetNode = treeView1.GetNodeAt(newPoint(e.X, e.Y));

Is there any differences from yours ?
"Michael" <in**@seeknsnatch.comwrote in message
news:44***********************@news.free.fr...
>When you receive your coordinates, they're actually with respect to the
screen. For you treeview to understand you need to change them to the
"client" equvalent.

Point newPoint = treeView1.PointToClient( new Point(e.X, e.Y));

MessageBox.Show(e.X.ToString() + " -- " + e.Y.ToString());

targetNode = treeView1.GetNodeAt(newPoint.X, newPoint.Y);

if (targetNode == null)

Mike

http://www.seeknsnatch.com

"Alan T" <al*************@yahoo.com.auwrote in message
news:e0**************@TK2MSFTNGP04.phx.gbl...
>>>I have a dragdrop event to capture the treenode that trigger that event.
However, I always get the returned node is null.

private void trvEmployee_DragDrop(object sender, DragEventArgs e)

{
TreeNode targetNode;

MessageBox.Show(e.X.ToString + " -- " + e.Y.ToString());
targetNode = trvEmployee.GetNodeAt(e.X, e.Y);
if (targetNode == null)
{ MessageBox.Show(" null");
}
else
{ MessageBox.Show(target.Text);
}
}

I don't know why it showed the e.X and e.Y have valid values but the
targetNode is null.

However, if I hardcode the
targetNode = trvEmployee.GetNodeAt(e.X, e.Y);
to e.X and e.Y to some value, it showed the node.
Note, the AllowDrop perperty has been set to true already.



Aug 15 '06 #4
Thanks Michael.
It works.

I missed this critical statement as you mentioned.
"Michael" <in**@seeknsnatch.comwrote in message
news:44***********************@news.free.fr...
yeah, you need this

Point newPoint = treeView1.PointToClient( new Point(e.X, e.Y));

Mike
http://www.seeknsnatch.com

"Alan T" <al*************@yahoo.com.auwrote in message
news:um**************@TK2MSFTNGP06.phx.gbl...
>Hi thanks.
I tried using one statement:
targetNode = treeView1.GetNodeAt(newPoint(e.X, e.Y));

Is there any differences from yours ?
"Michael" <in**@seeknsnatch.comwrote in message
news:44***********************@news.free.fr...
>>When you receive your coordinates, they're actually with respect to the
screen. For you treeview to understand you need to change them to the
"client" equvalent.

Point newPoint = treeView1.PointToClient( new Point(e.X, e.Y));

MessageBox.Show(e.X.ToString() + " -- " + e.Y.ToString());

targetNode = treeView1.GetNodeAt(newPoint.X, newPoint.Y);

if (targetNode == null)

Mike

http://www.seeknsnatch.com

"Alan T" <al*************@yahoo.com.auwrote in message
news:e0**************@TK2MSFTNGP04.phx.gbl...
I have a dragdrop event to capture the treenode that trigger that
event.
However, I always get the returned node is null.

private void trvEmployee_DragDrop(object sender, DragEventArgs e)

{
TreeNode targetNode;

MessageBox.Show(e.X.ToString + " -- " + e.Y.ToString());
targetNode = trvEmployee.GetNodeAt(e.X, e.Y);
if (targetNode == null)
{ MessageBox.Show(" null");
}
else
{ MessageBox.Show(target.Text);
}
}

I don't know why it showed the e.X and e.Y have valid values but the
targetNode is null.

However, if I hardcode the
targetNode = trvEmployee.GetNodeAt(e.X, e.Y);
to e.X and e.Y to some value, it showed the node.
Note, the AllowDrop perperty has been set to true already.





Aug 16 '06 #5

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

Similar topics

3
by: feel | last post by:
Goin' crazy with this recursive function ported from delphi... I send a string like DirA/ DirB /DirC but i get in the treeView each one in a new node.Cant get the child node....!! -DirA -DirB...
4
by: Phill | last post by:
Here's what I'm doing to make the right context mnue show up based on what node was cliked: private void tvwMenu_MouseUp(object sender, MouseEventArgs e) { //Select Node When Right Clicked &...
1
by: Aleksey | last post by:
Hi, All! I have a problem with TreeView component. My TreeView consists of two nodes Node1 and Node2. On click of right mouse button TreeView has event. In this event I check wich node is...
2
by: Randall Hale | last post by:
I'm trying to dynamically create values for a context menu (popup), depending upon which node is highlighted in a Treeview control. This is not a problem, if you select the node with the left...
6
by: rob willaar | last post by:
I seem to miss then treeview NodeClick How can i check if a node is clicked when it is selected?
3
by: Gary Dunne | last post by:
I'm writing an app that requires drag and drop operation between a ListView and a TreeView control. (The source is the ListView). During the drag drop operation I want to be able to detect the...
1
by: =?Utf-8?B?Q8Op?= | last post by:
I have the following bit of code, to handle an event when someone clicks on a treenode void myTreeview_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) { TreeView trv =...
3
by: sugee | last post by:
hi, I have a treeview when rightclicked a context menu should appear. but first time wen i right click the context menu of that node(ie, add,delete) appears whereas when i right click another...
3
by: dutsnekcirf | last post by:
I have a treeview control on a custom task pane in Excel. I've enable the ability to use Drag & Drop (by following this how-to) on the treeview to change the order of the nodes. The problem though...
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: 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
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...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.