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 4901
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: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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
|
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...
|
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...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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...
|
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,...
| |