|
I was thinking of something along the lines of:
When a node is selected, write its full path to originalPosition. When a destination is selected, write its full path to newPosition and:
IO.File.Copy(originalPosition, newPosition)
Is there a way to copy/move a file and its contents (including subfolders)?
Thanks
Brad
|
|
|
|
|
I've made a little more progress but now I'm stuck on a drag/drop problem.
Does anybody know how to store the fullpath of a selected node during a drag and drop procedure?
Here is what I have tried (in every variation that I can think of):
Dim originalPosition As String
Private sub [tried several methods]
originalPosition = TreeView1.SelectedNode.FullPath [...tried multiple properties]
End sub
At the start of the drag/drop the original path is stored in originalPosition but after the drag/drop is complete, originalPosition has changed to the new full path.
I don’t understand how this is happening. Does anybody understand the drag/drop procedures enough to see what is going on?
Here is the code that I'm using for the drag/drop:
Public Sub TreeView1_ItemDrag(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ItemDragEventArgs) Handles TreeView1.ItemDrag
DoDragDrop(e.Item, DragDropEffects.Move)
End Sub
Public Sub TreeView1_DragEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TreeView1.DragEnter
If e.Data.GetDataPresent("System.Windows.Forms.TreeNode", True) Then
e.Effect = DragDropEffects.Move
Else
e.Effect = DragDropEffects.None
End If
End Sub
Private Sub TreeView1_DragOver(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TreeView1.DragOver
If e.Data.GetDataPresent("System.Windows.Forms.TreeNode", True) = False Then Exit Sub
Dim selectedTreeview As TreeView = CType(sender, TreeView)
Dim pt As Point = CType(sender, TreeView).PointToClient(New Point(e.X, e.Y))
Dim targetNode As TreeNode = selectedTreeview.GetNodeAt(pt)
If Not (selectedTreeview Is targetNode) Then
selectedTreeview.SelectedNode = targetNode
Dim dropNode As TreeNode = CType(e.Data.GetData("System.Windows.Forms.TreeNode"), TreeNode)
Do Until targetNode Is Nothing
If targetNode Is dropNode Then
e.Effect = DragDropEffects.None
Exit Sub
End If
targetNode = targetNode.Parent
Loop
End If
e.Effect = DragDropEffects.Move
End Sub
Private Sub TreeView1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TreeView1.DragDrop
If e.Data.GetDataPresent("System.Windows.Forms.TreeNode", _
True) = False Then Exit Sub
Dim selectedTreeview As TreeView = CType(sender, TreeView)
Dim dropNode As TreeNode = _
CType(e.Data.GetData("System.Windows.Forms.TreeNode"), _
TreeNode)
Dim targetNode As TreeNode = selectedTreeview.SelectedNode
dropNode.Remove()
If targetNode Is Nothing Then
selectedTreeview.Nodes.Add(dropNode)
Else
targetNode.Nodes.Add(dropNode)
End If
dropNode.EnsureVisible()
selectedTreeview.SelectedNode = dropNode
End Sub
|
|
|
|
|
Why dont you store the original full path to TreeNode.Tag (when you are creating the node)?
|
|
|
|
|
|
Well ...
Have a WinApp ... I use a shared function in another class-project to write logs... Same Namespace ofcource.
The thing is I want to write down some properties in log. I want the properties to be VERY global =)) Can I declare some properties wich I can access even from referenced assemblies.
I can pass some arguments to my Log-function but If i can avoid it I'll be happy. Those properties are used all over my app/namespace.
Thnaks for your help //Maw
|
|
|
|
|
MaWeRic wrote:
The thing is I want to write down some properties in log. I want the properties to be VERY global =)) Can I declare some properties wich I can access even from referenced assemblies.
I have no idea what you're trying to say here.
All I can figure out is you have a shared function in a class that writes stuff to a log. Beyond that, I have no idea what your trying to do.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
MaWeRic wrote:
I want the properties to be VERY global =))
If you're using VB.NET, then you can't have globals. Global variables are a disaster, and a hallmark of bad programming. If you want something visible from everywhere, make it static, public, and put it on a class, which is your only option now that VB.NET makes VB an actual OO language, thus dragging it into the 1990's ( kicking and screaming, from what I can see ).
MaWeRic wrote:
I can pass some arguments to my Log-function but If i can avoid it I'll be happy.
If you don't pass them, how will they get there ? Surely you don't want to through away your class structure ( in terms of information hiding ) so that this class can grab whatever it likes from your entire application ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Christian Graus wrote:
so that this class can grab whatever it likes from your entire application
Heads on =)) That exactluy what. Make sure that sahred function can get information from MainApp whthout passing them ....
Soo?
//Maw
|
|
|
|
|
If you don't pass anything to the function, how on earth is it going to know what you want?
In order for this to work, EVERYTHING in your app that you want logged would have to be public and static. This is turning into a really bad idea.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
No, I have to disagree here. It's quite possible to acces private members of other classes using the System.Reflection namespace. Go look it up in the MSDN.
I can also sympathise with the intent of this question. For example, it would be handy if you could just call some kind of Save() function, and have every persistent variable (whether public or private) in your application saved out into an INI file. Then, call Load() and it all gets read in again.
I know it's possible because I've done it.
|
|
|
|
|
Dave knows about reflection. That doesn't mean it's a good suggestion in this case.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I should have clarified by saying "without going through the hassle of using Reflection to do it".
Yeah, I've done it too. But I at least put all my persistent stuff in my own settings class, kind of like the one in VB.NET 2005, so all I had to do was call Save() to spit it out. It even supported plug-ins so you could persist data to anywhere you could wrap a class around.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Well .... ow did you do it? Are you aware of that my application is using 2 different assemblies. Is it really possible to share information between assemblies without passing information?
If I stand in my logging function Intellisense only shows that assembli. I can in no way see the other part of the namespace.
//Maw
|
|
|
|
|
I've never had a case where I had to have multiple assemblies persisting their own properties. But, it wouldn't be hard. Each assembly can use its own copy of the Settings class.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Well ... a settings-class is a really really good idea =)) But can I make such class persist data thoughout several assemblies in a project? i.e set properties in one assemblie and read them in another?
How is that done? Can you give me a small example?
//Maw
|
|
|
|
|
Of course. There's no thing assembly specific about this. All it is is writing values to an XML file.
If you want a value to be used in multiple assemblies, all you have to do is expose a filename property and methods in the Settings class so you can tell it which file you want to load/save from/to.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
well it isn't nice ...... but it is a way of doing it. I aws lookin for someway of not writing to disk or registry..
//Maw
|
|
|
|
|
Then how do you expect to "persist" the data? It normally means to make it persistant between executions of your application.
Now, you're talking about interprocess communication...
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
A class with public static methods - then you don't need an instance, and you can call it from anywhere. I've done logging like this. I actually said this in my first reply.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
As I said in earlier thread ...
My application consists of many different assemblies. Logging is in one assemblie and mainapp is in another.
Can you give me information about how you did it ...
If I stand in my logging function Intellisense only shows that assembli. I can in no way see the other part of the namespace.
//Maw
|
|
|
|
|
My advice is the same - have a logging class which is given the information to log, making a class able to see everything across all your assemblies is just a bad idea. If you want your logging to always store the same info, add methods on the classes so you can get it, as a string so that it's human readable, but not machine readable.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Can you give me an example of your suggestion in code?
//Maw
|
|
|
|
|
I don't do VB, but here's some C#.
class Logging
{
public static void Log(string message)
{
// Access the log file via a lazy initialised property
// Write the message to the log file
}
}
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Well .... thats how I d it today .... Only part I'm missing is how I'll get the properties over there like username and "function" and so on. Maybe the best way is a settingsclass wich reads from an XML-file. Maybe Serialization is good idea here.
//Maw
|
|
|
|
|
MaWeRic wrote:
Only part I'm missing is how I'll get the properties over there like username and "function" and so on.
You need to pass them through. How else would you do it, generically ?
Christian Graus - Microsoft MVP - C++
|
|
|
|