Hello,
I knew how to use the treeview under VB6. After migrating to .NET, well, I'm
lost.
I try to add a new node, either to the same level or as a child to a
selected node in the treeview.
However, either it only add it to the root level or it only add it on level
below, doesn't matter what I select. And in some case, I just get an
exception.
Does anyone have a short example of how to add a new node (same level/child)
to an existing treeview based on a selected node ?
I'm pretty sure I mess up with the index, but I'm really lost.
Here is what I do to add same level:
Sub InsertNode(ByRef TreeviewRef As System.Windows.Forms.TreeView, ByVal
ImgIndex As Integer, ByVal SelImgIndex As Integer, ByVal NText As String,
ByVal NIndex As Integer, ByVal NTag As String)
' Add a node to a treeview. node will be added before the selection index.
' In : treeview, imgindex,selimgindex,ntext,index,tag
' Out : -
' Ret : -
' Call ex: InsertNode(MainTreeView, 0, 0, "Root",675,"tag")
Dim oNode As New System.Windows.Forms.TreeNode
oNode.ImageIndex = ImgIndex
oNode.SelectedImageIndex = SelImgIndex
oNode.Text = NText
oNode.Tag = NTag
TreeviewRef.Nodes.Insert(NIndex, oNode)
And what I do for child level:
Sub AddChildrenNode(ByRef TreeviewRef As System.Windows.Forms.TreeView,
ByVal NIndex As Integer, ByVal NTag As String)
' Add a children a node to a treeview under the current selection.
' In : treeview, index, tag
' Out : -
' Ret : -
' Call ex: AddChildrenNode(MainTreeView, 675, "xxx")
Dim oNode As New System.Windows.Forms.TreeNode
oNode.ImageIndex = 0
oNode.SelectedImageIndex = 0
oNode.Text = "toto"
oNode.Tag = NTag
TreeviewRef.Nodes(NIndex).Nodes.Add(oNode)
TreeviewRef.Nodes(NIndex).Expand()
End Sub
Thanks. 6 4896
Adding a new node to the selected node is done something like this:
' Create the new node
Dim myNewNode as new TreeNode
....
....
' Get the currently selected node
Dim theSelectedNode as TreeNode = myTree.SelectedNode
If not theSelectedNode is nothing then
theSelectedNode.Nodes.Add ( myNewNode)
Else
' Error, attempting to add a new node when no node has been selected.
End If
"L.M" <nospam> wrote in message
news:OI**************@TK2MSFTNGP15.phx.gbl... Hello,
I knew how to use the treeview under VB6. After migrating to .NET, well, I'm lost. I try to add a new node, either to the same level or as a child to a selected node in the treeview. However, either it only add it to the root level or it only add it on level below, doesn't matter what I select. And in some case, I just get an exception.
Does anyone have a short example of how to add a new node (same level/child) to an existing treeview based on a selected node ?
I'm pretty sure I mess up with the index, but I'm really lost.
Here is what I do to add same level:
Sub InsertNode(ByRef TreeviewRef As System.Windows.Forms.TreeView, ByVal ImgIndex As Integer, ByVal SelImgIndex As Integer, ByVal NText As String, ByVal NIndex As Integer, ByVal NTag As String) ' Add a node to a treeview. node will be added before the selection index. ' In : treeview, imgindex,selimgindex,ntext,index,tag ' Out : - ' Ret : - ' Call ex: InsertNode(MainTreeView, 0, 0, "Root",675,"tag") Dim oNode As New System.Windows.Forms.TreeNode oNode.ImageIndex = ImgIndex oNode.SelectedImageIndex = SelImgIndex oNode.Text = NText oNode.Tag = NTag TreeviewRef.Nodes.Insert(NIndex, oNode)
And what I do for child level:
Sub AddChildrenNode(ByRef TreeviewRef As System.Windows.Forms.TreeView, ByVal NIndex As Integer, ByVal NTag As String) ' Add a children a node to a treeview under the current selection. ' In : treeview, index, tag ' Out : - ' Ret : - ' Call ex: AddChildrenNode(MainTreeView, 675, "xxx")
Dim oNode As New System.Windows.Forms.TreeNode oNode.ImageIndex = 0 oNode.SelectedImageIndex = 0 oNode.Text = "toto" oNode.Tag = NTag TreeviewRef.Nodes(NIndex).Nodes.Add(oNode) TreeviewRef.Nodes(NIndex).Expand() End Sub
Thanks.
Hello,
That make it, thanks a lot. It seems that the Index in the .Net treeview is
based on each node collection and not on the whole treeview content....
Might be a good thing as soon as you get used to it....
Next step is the drap and drop, it works fine. I just have the mouse pointer
instead of the node text+icon as in VB6.
"Robin Tucker" <id*************************@reallyidont.com> wrote in
message news:cj*******************@news.demon.co.uk... Adding a new node to the selected node is done something like this:
' Create the new node
Dim myNewNode as new TreeNode ... ...
' Get the currently selected node
Dim theSelectedNode as TreeNode = myTree.SelectedNode
If not theSelectedNode is nothing then
theSelectedNode.Nodes.Add ( myNewNode)
Else
' Error, attempting to add a new node when no node has been selected.
End If
"L.M" <nospam> wrote in message news:OI**************@TK2MSFTNGP15.phx.gbl... Hello,
I knew how to use the treeview under VB6. After migrating to .NET, well, I'm lost. I try to add a new node, either to the same level or as a child to a selected node in the treeview. However, either it only add it to the root level or it only add it on level below, doesn't matter what I select. And in some case, I just get an exception.
Does anyone have a short example of how to add a new node (same level/child) to an existing treeview based on a selected node ?
I'm pretty sure I mess up with the index, but I'm really lost.
Here is what I do to add same level:
Sub InsertNode(ByRef TreeviewRef As System.Windows.Forms.TreeView, ByVal ImgIndex As Integer, ByVal SelImgIndex As Integer, ByVal NText As
String, ByVal NIndex As Integer, ByVal NTag As String) ' Add a node to a treeview. node will be added before the selection
index. ' In : treeview, imgindex,selimgindex,ntext,index,tag ' Out : - ' Ret : - ' Call ex: InsertNode(MainTreeView, 0, 0, "Root",675,"tag") Dim oNode As New System.Windows.Forms.TreeNode oNode.ImageIndex = ImgIndex oNode.SelectedImageIndex = SelImgIndex oNode.Text = NText oNode.Tag = NTag TreeviewRef.Nodes.Insert(NIndex, oNode)
And what I do for child level:
Sub AddChildrenNode(ByRef TreeviewRef As System.Windows.Forms.TreeView, ByVal NIndex As Integer, ByVal NTag As String) ' Add a children a node to a treeview under the current selection. ' In : treeview, index, tag ' Out : - ' Ret : - ' Call ex: AddChildrenNode(MainTreeView, 675, "xxx")
Dim oNode As New System.Windows.Forms.TreeNode oNode.ImageIndex = 0 oNode.SelectedImageIndex = 0 oNode.Text = "toto" oNode.Tag = NTag TreeviewRef.Nodes(NIndex).Nodes.Add(oNode) TreeviewRef.Nodes(NIndex).Expand() End Sub
Thanks.
Item drag and drag drop.....
Private Sub TreeView_ItemDrag(ByVal sender As Object, ByVal e As
System.Windows.Forms.ItemDragEventArgs) Handles TreeView.ItemDrag
If e.Item Is Nothing Then
Exit Sub
End If
' Start the drag operation
DoDragDrop(...whatever I'm dragging...maybe a tree node (ie.
SelectedNode), DragDropEffects.Move Or DragDropEffects.Copy)
End Sub
Private Sub TreeView_DragDrop(ByVal sender As Object, ByVal e As
System.Windows.Forms.DragEventArgs) Handles TreeView.DragDrop
Dim mousePos As Point
mousePos = TreeView.PointToClient(New Point(e.X, e.Y))
Dim nodeOver As TreeNode = TreeView.GetNodeAt(mousePos)
If nodeOver Is Nothing Then
' not dropping on a tree node...
Else
' dropping onto "node over"
End If
End Sub
"L.M" <nospam> wrote in message
news:%2****************@tk2msftngp13.phx.gbl... Hello,
That make it, thanks a lot. It seems that the Index in the .Net treeview is based on each node collection and not on the whole treeview content.... Might be a good thing as soon as you get used to it....
Next step is the drap and drop, it works fine. I just have the mouse pointer instead of the node text+icon as in VB6. "Robin Tucker" <id*************************@reallyidont.com> wrote in message news:cj*******************@news.demon.co.uk... Adding a new node to the selected node is done something like this:
' Create the new node
Dim myNewNode as new TreeNode ... ...
' Get the currently selected node
Dim theSelectedNode as TreeNode = myTree.SelectedNode
If not theSelectedNode is nothing then
theSelectedNode.Nodes.Add ( myNewNode)
Else
' Error, attempting to add a new node when no node has been selected.
End If
"L.M" <nospam> wrote in message news:OI**************@TK2MSFTNGP15.phx.gbl... > Hello, > > I knew how to use the treeview under VB6. After migrating to .NET, > well, > I'm > lost. > I try to add a new node, either to the same level or as a child to a > selected node in the treeview. > However, either it only add it to the root level or it only add it on > level > below, doesn't matter what I select. And in some case, I just get an > exception. > > Does anyone have a short example of how to add a new node (same > level/child) > to an existing treeview based on a selected node ? > > I'm pretty sure I mess up with the index, but I'm really lost. > > Here is what I do to add same level: > > Sub InsertNode(ByRef TreeviewRef As System.Windows.Forms.TreeView, > ByVal > ImgIndex As Integer, ByVal SelImgIndex As Integer, ByVal NText As String, > ByVal NIndex As Integer, ByVal NTag As String) > ' Add a node to a treeview. node will be added before the selection index. > ' In : treeview, imgindex,selimgindex,ntext,index,tag > ' Out : - > ' Ret : - > ' Call ex: InsertNode(MainTreeView, 0, 0, "Root",675,"tag") > Dim oNode As New System.Windows.Forms.TreeNode > oNode.ImageIndex = ImgIndex > oNode.SelectedImageIndex = SelImgIndex > oNode.Text = NText > oNode.Tag = NTag > TreeviewRef.Nodes.Insert(NIndex, oNode) > > > And what I do for child level: > > Sub AddChildrenNode(ByRef TreeviewRef As System.Windows.Forms.TreeView, > ByVal NIndex As Integer, ByVal NTag As String) > ' Add a children a node to a treeview under the current selection. > ' In : treeview, index, tag > ' Out : - > ' Ret : - > ' Call ex: AddChildrenNode(MainTreeView, 675, "xxx") > > Dim oNode As New System.Windows.Forms.TreeNode > oNode.ImageIndex = 0 > oNode.SelectedImageIndex = 0 > oNode.Text = "toto" > oNode.Tag = NTag > TreeviewRef.Nodes(NIndex).Nodes.Add(oNode) > TreeviewRef.Nodes(NIndex).Expand() > End Sub > > > Thanks. > > >
Thanks, that's what I had, in a less nice way, but the same. However, is
there a way to get the icone/text under the mouse as it was in VB6 (or in
windows explorer when you drap/drop file/folder) ?
The funtion I was using in VB6 doesn't seems to exist anymore in .Net.
L.M
"Robin Tucker" <id*************************@reallyidont.com> wrote in
message news:cj*******************@news.demon.co.uk... Item drag and drag drop.....
Private Sub TreeView_ItemDrag(ByVal sender As Object, ByVal e As System.Windows.Forms.ItemDragEventArgs) Handles TreeView.ItemDrag
If e.Item Is Nothing Then Exit Sub End If
' Start the drag operation
DoDragDrop(...whatever I'm dragging...maybe a tree node (ie. SelectedNode), DragDropEffects.Move Or DragDropEffects.Copy)
End Sub
Private Sub TreeView_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TreeView.DragDrop
Dim mousePos As Point
mousePos = TreeView.PointToClient(New Point(e.X, e.Y))
Dim nodeOver As TreeNode = TreeView.GetNodeAt(mousePos)
If nodeOver Is Nothing Then
' not dropping on a tree node...
Else
' dropping onto "node over"
End If
End Sub
"L.M" <nospam> wrote in message news:%2****************@tk2msftngp13.phx.gbl... Hello,
That make it, thanks a lot. It seems that the Index in the .Net treeview is based on each node collection and not on the whole treeview content.... Might be a good thing as soon as you get used to it....
Next step is the drap and drop, it works fine. I just have the mouse pointer instead of the node text+icon as in VB6. "Robin Tucker" <id*************************@reallyidont.com> wrote in message news:cj*******************@news.demon.co.uk... Adding a new node to the selected node is done something like this:
' Create the new node
Dim myNewNode as new TreeNode ... ...
' Get the currently selected node
Dim theSelectedNode as TreeNode = myTree.SelectedNode
If not theSelectedNode is nothing then
theSelectedNode.Nodes.Add ( myNewNode)
Else
' Error, attempting to add a new node when no node has been
selected. End If
"L.M" <nospam> wrote in message news:OI**************@TK2MSFTNGP15.phx.gbl... > Hello, > > I knew how to use the treeview under VB6. After migrating to .NET, > well, > I'm > lost. > I try to add a new node, either to the same level or as a child to a > selected node in the treeview. > However, either it only add it to the root level or it only add it on > level > below, doesn't matter what I select. And in some case, I just get an > exception. > > Does anyone have a short example of how to add a new node (same > level/child) > to an existing treeview based on a selected node ? > > I'm pretty sure I mess up with the index, but I'm really lost. > > Here is what I do to add same level: > > Sub InsertNode(ByRef TreeviewRef As System.Windows.Forms.TreeView, > ByVal > ImgIndex As Integer, ByVal SelImgIndex As Integer, ByVal NText As String, > ByVal NIndex As Integer, ByVal NTag As String) > ' Add a node to a treeview. node will be added before the selection index. > ' In : treeview, imgindex,selimgindex,ntext,index,tag > ' Out : - > ' Ret : - > ' Call ex: InsertNode(MainTreeView, 0, 0, "Root",675,"tag") > Dim oNode As New System.Windows.Forms.TreeNode > oNode.ImageIndex = ImgIndex > oNode.SelectedImageIndex = SelImgIndex > oNode.Text = NText > oNode.Tag = NTag > TreeviewRef.Nodes.Insert(NIndex, oNode) > > > And what I do for child level: > > Sub AddChildrenNode(ByRef TreeviewRef As
System.Windows.Forms.TreeView, > ByVal NIndex As Integer, ByVal NTag As String) > ' Add a children a node to a treeview under the current selection. > ' In : treeview, index, tag > ' Out : - > ' Ret : - > ' Call ex: AddChildrenNode(MainTreeView, 675, "xxx") > > Dim oNode As New System.Windows.Forms.TreeNode > oNode.ImageIndex = 0 > oNode.SelectedImageIndex = 0 > oNode.Text = "toto" > oNode.Tag = NTag > TreeviewRef.Nodes(NIndex).Nodes.Add(oNode) > TreeviewRef.Nodes(NIndex).Expand() > End Sub > > > Thanks. > > >
Not sure what you mean by Icon/Text under the mouse. When dragging from
explorer, you will have a String() array (I expect) in the Data property.
ie. :
' Determine if the drag drop is one of our supported drop formats
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
' Get the files...
Dim theFiles As String() =
DirectCast(e.Data.GetData(DataFormats.FileDrop), String())
.....
End If
End If
"L.M" <nospam> wrote in message
news:eT**************@TK2MSFTNGP15.phx.gbl... Thanks, that's what I had, in a less nice way, but the same. However, is there a way to get the icone/text under the mouse as it was in VB6 (or in windows explorer when you drap/drop file/folder) ? The funtion I was using in VB6 doesn't seems to exist anymore in .Net.
L.M "Robin Tucker" <id*************************@reallyidont.com> wrote in message news:cj*******************@news.demon.co.uk... Item drag and drag drop.....
Private Sub TreeView_ItemDrag(ByVal sender As Object, ByVal e As System.Windows.Forms.ItemDragEventArgs) Handles TreeView.ItemDrag
If e.Item Is Nothing Then Exit Sub End If
' Start the drag operation
DoDragDrop(...whatever I'm dragging...maybe a tree node (ie. SelectedNode), DragDropEffects.Move Or DragDropEffects.Copy)
End Sub
Private Sub TreeView_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TreeView.DragDrop
Dim mousePos As Point
mousePos = TreeView.PointToClient(New Point(e.X, e.Y))
Dim nodeOver As TreeNode = TreeView.GetNodeAt(mousePos)
If nodeOver Is Nothing Then
' not dropping on a tree node...
Else
' dropping onto "node over"
End If
End Sub
"L.M" <nospam> wrote in message news:%2****************@tk2msftngp13.phx.gbl... > Hello, > > That make it, thanks a lot. It seems that the Index in the .Net > treeview > is > based on each node collection and not on the whole treeview content.... > Might be a good thing as soon as you get used to it.... > > Next step is the drap and drop, it works fine. I just have the mouse > pointer > instead of the node text+icon as in VB6. > > > > "Robin Tucker" <id*************************@reallyidont.com> wrote in > message news:cj*******************@news.demon.co.uk... >> Adding a new node to the selected node is done something like this: >> >> ' Create the new node >> >> Dim myNewNode as new TreeNode >> ... >> ... >> >> ' Get the currently selected node >> >> Dim theSelectedNode as TreeNode = myTree.SelectedNode >> >> If not theSelectedNode is nothing then >> >> theSelectedNode.Nodes.Add ( myNewNode) >> >> Else >> >> ' Error, attempting to add a new node when no node has been selected. >> >> End If >> >> "L.M" <nospam> wrote in message >> news:OI**************@TK2MSFTNGP15.phx.gbl... >> > Hello, >> > >> > I knew how to use the treeview under VB6. After migrating to .NET, >> > well, >> > I'm >> > lost. >> > I try to add a new node, either to the same level or as a child to a >> > selected node in the treeview. >> > However, either it only add it to the root level or it only add it >> > on >> > level >> > below, doesn't matter what I select. And in some case, I just get an >> > exception. >> > >> > Does anyone have a short example of how to add a new node (same >> > level/child) >> > to an existing treeview based on a selected node ? >> > >> > I'm pretty sure I mess up with the index, but I'm really lost. >> > >> > Here is what I do to add same level: >> > >> > Sub InsertNode(ByRef TreeviewRef As System.Windows.Forms.TreeView, >> > ByVal >> > ImgIndex As Integer, ByVal SelImgIndex As Integer, ByVal NText As > String, >> > ByVal NIndex As Integer, ByVal NTag As String) >> > ' Add a node to a treeview. node will be added before the selection > index. >> > ' In : treeview, imgindex,selimgindex,ntext,index,tag >> > ' Out : - >> > ' Ret : - >> > ' Call ex: InsertNode(MainTreeView, 0, 0, "Root",675,"tag") >> > Dim oNode As New System.Windows.Forms.TreeNode >> > oNode.ImageIndex = ImgIndex >> > oNode.SelectedImageIndex = SelImgIndex >> > oNode.Text = NText >> > oNode.Tag = NTag >> > TreeviewRef.Nodes.Insert(NIndex, oNode) >> > >> > >> > And what I do for child level: >> > >> > Sub AddChildrenNode(ByRef TreeviewRef As System.Windows.Forms.TreeView, >> > ByVal NIndex As Integer, ByVal NTag As String) >> > ' Add a children a node to a treeview under the current selection. >> > ' In : treeview, index, tag >> > ' Out : - >> > ' Ret : - >> > ' Call ex: AddChildrenNode(MainTreeView, 675, "xxx") >> > >> > Dim oNode As New System.Windows.Forms.TreeNode >> > oNode.ImageIndex = 0 >> > oNode.SelectedImageIndex = 0 >> > oNode.Text = "toto" >> > oNode.Tag = NTag >> > TreeviewRef.Nodes(NIndex).Nodes.Add(oNode) >> > TreeviewRef.Nodes(NIndex).Expand() >> > End Sub >> > >> > >> > Thanks. >> > >> > >> > >> >> > >
I mean an equivalent to :
TreeView1.DragIcon = TreeView1.SelectedItem.CreateDragImage
from VB6 but in VB.Net
"Robin Tucker" <id*************************@reallyidont.com> wrote in
message news:cj*******************@news.demon.co.uk... Not sure what you mean by Icon/Text under the mouse. When dragging from explorer, you will have a String() array (I expect) in the Data property.
ie. :
' Determine if the drag drop is one of our supported drop formats
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
' Get the files...
Dim theFiles As String() = DirectCast(e.Data.GetData(DataFormats.FileDrop), String())
.....
End If
End If This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Steve |
last post by:
Visual Studio 2003 .NET / C#
I have a treeview object on a form which acts as the main menu controller
for my application. the treeview is always in sight, and the form it is on
acts as the...
|
by: Brian Smith |
last post by:
Is there a way to avoid the default action of TreeNode expansion/contraction
caused by double click? I can add an event handler to pop up my properties
dialog on double click, but it has the...
|
by: Soul |
last post by:
Hi,
I am learning C# at the moment. I am trying to develop a simple program that
will get data from a MS Access database into a dataSet. The result of
dataSet should be something like:
Year ...
|
by: Rasmus |
last post by:
I need to grab focus to a specific node i my treeview when I click on my listbox.
Here's the code that differs between the different event i the listBox:
private void...
|
by: Shailendra Batham |
last post by:
Hey guys
I am using the IE Web controls treeview control.
I popuplate the treeview with XML and it looks fine........... my question
is how can I add a right click popup menu to the treeview...
|
by: Chris Marsh |
last post by:
I have setup a treeview on my XP desktop and it displays data yet on the
Windows 2003 Server it will not display the treeview. Does anyone have a
clue on how to make this function on 2003 Server?...
|
by: Evan Kontos |
last post by:
I am trying to implement a Treeview w/an XML file and I even copied and
pasted examples from MSDN but can't get them to work. Any suggestions
welcome.
XML File
<TREENODES>
<TREENODE...
|
by: david |
last post by:
I do not know if there is a treeView control for web form in .NET 1.1.
I know there is IE Webcontrol package which has the treeview control for
..net 1.0. I have tested it in .net 1.1 before. It...
|
by: casManG |
last post by:
I am working on a small project that uses the treeview control in .net
2003. I have a tree view that I am sending to a sub in order to
iterate through the nodes.
Public Sub test (ByVal...
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: Aftab Ahmad |
last post by:
Hello Experts!
I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
|
by: Aftab Ahmad |
last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below.
Dim IE As Object
Set IE =...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
| |