473,382 Members | 1,814 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,382 software developers and data experts.

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(Control.MousePosition);

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(Form.MousePosition);

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(object sender, ItemDragEventArgs e)
{
//PROBLEM: not getting ghost image, probably due to incorrect mouse
coordinates
TreeView tree = (TreeView)sender;
dragNode = (TreeNode)e.Item;
tree.SelectedNode = dragNode;
imageListDrag.Images.Clear();
imageListDrag.ImageSize = new Size(dragNode.Bounds.Size.Width +
tree.Indent, dragNode.Bounds.Height);
Bitmap bmp = new Bitmap(dragNode.Bounds.Width + tree.Indent,
dragNode.Bounds.Height);
Graphics gfx = Graphics.FromImage(bmp);
gfx.DrawImage(imageListConfiguration.Images[0], 0, 0);
// optional: Draw node label into bitmap
//gfx.DrawString("CFG", tree.Font, new SolidBrush(tree.ForeColor),
(float)tree.Indent, 1.0f);
imageListDrag.Images.Add(bmp);
//imageListDrag.Images.Add(ImageHelper.getImage(fold er));
//Point p = tree.PointToClient(Control.MousePosition);
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Point p = tree.PointToClient(Form.MousePosition); //does not help
int dx = p.X + tree.Indent - dragNode.Bounds.Left;
int dy = p.Y - dragNode.Bounds.Top;
if (TreeHelper.ImageList_BeginDrag(imageListDrag.Hand le, 0, dx, dy))
{
tree.DoDragDrop(bmp, DragDropEffects.Move);
TreeHelper.ImageList_EndDrag();
}
}

Mar 2 '06 #1
0 3447

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

Similar topics

3
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...
6
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...
13
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...
2
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...
2
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...
0
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...
6
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...
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. ...
1
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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.