473,803 Members | 3,461 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to get coordinates of node in TreeView?

I'm trying to implement a custom TreeView that shows a ghost image while
dragging. But the form I'm using is different from the sample code found
here: http://www.codeproject.com/cs/miscct...ewDragDrop.asp

The problem is I can't get the proper coordinates required when dragging
begins. I have two tree views in a panel with a splitter, and the panel is
on a TabControl.

The sample code just has a simple form with the treeview control filling the
form.

Here is how the sample gets coordinates:

Point pt = PointToClient(C ontrol.MousePos ition);

In my implementation, that provides incorrect coordinates.

I have a splitter (to make one tree smaller and one larger) which means the
tree on the left is docked LEFT and the one on the right is docked FILL.
Does this mean both TreeView's coordinates start at the left edge of the
panel?

I've tried this:

Point pt = PointToClient(F orm.MousePositi on);

but no luck...

Below is more complete code.

What is the best way to get the coordinates of the node which is about to be
dragged so I can get a ghost image?

Thanks in advance.

private void tree_ItemDrag(o bject sender, ItemDragEventAr gs e)
{
//PROBLEM: not getting ghost image, probably due to incorrect mouse
coordinates
TreeView tree = (TreeView)sende r;
dragNode = (TreeNode)e.Ite m;
tree.SelectedNo de = dragNode;
imageListDrag.I mages.Clear();
imageListDrag.I mageSize = new Size(dragNode.B ounds.Size.Widt h +
tree.Indent, dragNode.Bounds .Height);
Bitmap bmp = new Bitmap(dragNode .Bounds.Width + tree.Indent,
dragNode.Bounds .Height);
Graphics gfx = Graphics.FromIm age(bmp);
gfx.DrawImage(i mageListConfigu ration.Images[0], 0, 0);
// optional: Draw node label into bitmap
//gfx.DrawString( "CFG", tree.Font, new SolidBrush(tree .ForeColor),
(float)tree.Ind ent, 1.0f);
imageListDrag.I mages.Add(bmp);
//imageListDrag.I mages.Add(Image Helper.getImage (folder));
//Point p = tree.PointToCli ent(Control.Mou sePosition);
//!!!!!!!!!!!!!!! !!!!!!!!!!!!!!! !!!!
Point p = tree.PointToCli ent(Form.MouseP osition); //does not help
int dx = p.X + tree.Indent - dragNode.Bounds .Left;
int dy = p.Y - dragNode.Bounds .Top;
if (TreeHelper.Ima geList_BeginDra g(imageListDrag .Handle, 0, dx, dy))
{
tree.DoDragDrop (bmp, DragDropEffects .Move);
TreeHelper.Imag eList_EndDrag() ;
}
}

Mar 2 '06 #1
0 3479

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

Similar topics

3
6063
by: Saradhi | last post by:
Hi All, Here I am facing a performance problem with the TreeView Node renaming. I am displaying a hierarchy Data in a treeview in my Windows C# Application. My tree view represents an hierarchical view of Parent Nodes and projects where in a projectnode can be added to any ParentNode and hence we may have a project node added to 100 Parent nodes. In this one, I have an operation of Renaming a Project Node. So whenever I am doing the...
6
6731
by: Tim | last post by:
Hi I have a form with a treeview on it. When I select a particular node it adds/shows a tab on the form. The treeview node remains selected as it should. The user can close the tab or remove the focus to another tab. Clicking on the same already selected node should add/show the tab, however the after select event does not fire as the node is already selected. I trapped the click event of the treeview but that is not node specific. In...
13
9066
by: André Nogueira | last post by:
Hi there. I know you can view a node's fullpath property, but is it posible to select a node using its path? Like, tell the treeview that the node that should be selected is the node with the path "Users\Administrators\John Doe"? Thank you in advance! Andre Nogueira
2
2681
by: kevin | last post by:
I would like to remember the state of the nodes after the treeview gets disposed, but not necessarily after the app terminates so I don't need a disk file. I was thinking about using the tag property, but I am already using it, so then I though about making a custom treeiew using inheritance and adding another tag type property? Any clues? kevin
2
7502
by: Tymbow | last post by:
I'm building a web application that is analogous to the Windows XP file explorer in function. The left column contains a TreeView, and the right column a DataGrid populated by selecting TreeView nodes. The TreeView populates dynamically as there are a significant number of nodes. The DataGrid displays both the items and the nodes from the TreeView. Using the explorer analogy this means the TreeView shows folders, and the DataGrid folders...
0
12793
by: jiing | last post by:
Hi all, I want to use sting(the same as Node.Text) to judge if a node exists in TreeView. I've tried several ways, but seems all failed. could anybody help me? Thanks in advance. //My TreeView is defined to has depth =3 only.
6
11972
by: xla76 | last post by:
I have a simple treeview (treeview1) to which I have added two nodes (nodeA and nodeB) which have n levels of child nodes. What I want is to be able to identify whether the child node I select is under NodeA or NodeB. I can do this by splitting the selectednode.fullpath of the child node but there must be a better way. Can any kind soul can enlighten me?
0
3315
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. Provide following view properties to listview, through View menu a. Tile b. Icon
1
3942
by: =?Utf-8?B?Rmx5Z3V5?= | last post by:
I have a TreeView with so many nodes that it requires scroll bars. When the user selects a node the screen is refreshed and the selected node is no longer visible. The TreeView is opened to the selected node but the screen is not scrolled to it. How can I get the TreeView to show the selected node after it has been refreshed?
0
10550
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10317
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10069
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6844
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5501
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5633
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4275
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3799
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2972
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.