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

How can I select only the parent node of a treeview treenode?

I have searched everywhere and tried several things. I have a
treeview with and want to be able to only select a parent node. For
example:

root //don't want to drag this
-parent1 //yes, drag this an only this because it is a parent
--childOfParent1 //cannot drag this, only the parent
--childOfParent1 //can only drag parent
-parent2 //yes, parent, can select and drag
--childOfParent2 //no, cannot drag
....

I have tried various, but this was the last:

private void trvPapers_ItemDrag(object sender, ItemDragEventArgs
e)
{
TreeNode sourceNode = (TreeNode)e.Item;
if (sourceNode.Parent != null &&
sourceNode.Parent.IsSelected)
DoDragDrop(e.Item, DragDropEffects.Move);

}

fails. I don't get an error, just strange behavior and it doesn't do
what it's supposed to. Any help is appreciated. How can I only drag
parents along with their children? I don't want the user to drag the
children anywhere alone. I only want the parent and children to go
together. FWIW, my drag and drop works, I just can't limit it. Thank
you.
Jul 14 '08 #1
4 3567
On Mon, 14 Jul 2008 11:00:37 -0700, jmDesktop <ne***********@gmail.com>
wrote:
[...] How can I only drag
parents along with their children? I don't want the user to drag the
children anywhere alone. I only want the parent and children to go
together. FWIW, my drag and drop works, I just can't limit it. Thank
you.
I'm having a hard time understanding what you're asking. So you may want
to try to be more explicit. However, the code you posted looks to me as
though it would only drag the specific item that generated the ItemDrag
event. Maybe instead you want to call DoDragDrop() with
"sourceNode.Parent" instead of "e.Item"?

Pete

Jul 14 '08 #2
On Jul 14, 10:00*pm, jmDesktop <needin4mat...@gmail.comwrote:
I have searched everywhere and tried several things. *I have a
treeview with and want to be able to only select a parent node. For
example:

root //don't want to drag this
-parent1 //yes, drag this an only this because it is a parent
--childOfParent1 //cannot drag this, only the parent
--childOfParent1 //can only drag parent
-parent2 //yes, parent, can select and drag
--childOfParent2 //no, cannot drag
...

I have tried various, but this was the last:

* * *private void trvPapers_ItemDrag(object sender, ItemDragEventArgs
e)
* * * * {
* * * * * * TreeNode sourceNode = (TreeNode)e.Item;
* * * * * * if (sourceNode.Parent != null &&
sourceNode.Parent.IsSelected)
* * * * * * * * DoDragDrop(e.Item, DragDropEffects.Move);

* * * * }
If you want to do what I think you do, then it won't work. Consider:
root node has Parent==null. All parent* nodes have Parent==root. All
child* nodes have Parent=parent*. So if you want to only drag parent*
nodes, you can simply check that node.Parent==root (and root would be
TreeView.Nodes[0] in your case).
Jul 15 '08 #3
On Jul 15, 2:30*am, Pavel Minaev <int...@gmail.comwrote:
On Jul 14, 10:00*pm, jmDesktop <needin4mat...@gmail.comwrote:


I have searched everywhere and tried several things. *I have a
treeview with and want to be able to only select a parent node. For
example:
root //don't want to drag this
-parent1 //yes, drag this an only this because it is a parent
--childOfParent1 //cannot drag this, only the parent
--childOfParent1 //can only drag parent
-parent2 //yes, parent, can select and drag
--childOfParent2 //no, cannot drag
...
I have tried various, but this was the last:
* * *private void trvPapers_ItemDrag(object sender, ItemDragEventArgs
e)
* * * * {
* * * * * * TreeNode sourceNode = (TreeNode)e.Item;
* * * * * * if (sourceNode.Parent != null &&
sourceNode.Parent.IsSelected)
* * * * * * * * DoDragDrop(e.Item, DragDropEffects.Move);
* * * * }

If you want to do what I think you do, then it won't work. Consider:
root node has Parent==null. All parent* nodes have Parent==root. All
child* nodes have Parent=parent*. So if you want to only drag parent*
nodes, you can simply check that node.Parent==root (and root would be
TreeView.Nodes[0] in your case).- Hide quoted text -

- Show quoted text -
I ended up with what I think is a hack, but maybe not:

TreeNode sourceNode = (TreeNode)e.Item;
if (sourceNode.Parent != null) //check for root
{
if (sourceNode.Parent.Text == "myRootNodeText")
{
DoDragDrop(sourceNode, DragDropEffects.Move);
}
}
Jul 15 '08 #4
On Jul 15, 5:49*pm, jmDesktop <needin4mat...@gmail.comwrote:
I ended up with what I think is a hack, but maybe not:

TreeNode sourceNode = (TreeNode)e.Item;
* * * * * * if (sourceNode.Parent != null) //check for root
* * * * * * {
* * * * * * * * if (sourceNode.Parent.Text == "myRootNodeText")
* * * * * * * * {
* * * * * * * * * * DoDragDrop(sourceNode, DragDropEffects.Move);
* * * * * * * * }
* * * * * * }
It is a hack if you want to consider localization. Why not Nodes[0],
anyway?
Jul 15 '08 #5

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

Similar topics

1
by: clintonG | last post by:
How do I get a TreeNode.Parent property when using the 2.0 TreeView control? When the data source is an XML file there may be redundant names in the tree. For example, when a child node with 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: 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...
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...
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...
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: SQACSharp | last post by:
I'm using the EnumChildWindows API with an EnumChildWndProc callback to populate the treeview. The output will be something similar to spy+ + How can I specify the parent when adding a new node...
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: dmeglio | last post by:
I have a treeview control. The "root" elements and the 2nd level elements are set to PopulateOnDemand. All is fine, my TreeNodePopulate triggers and works. When you click one of those nodes, I load...
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: 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?
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:
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
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...

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.