Autor Beitrag
Christoph1972
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 690
Erhaltene Danke: 16


VS2015 Pro / C# & VB.Net
BeitragVerfasst: Fr 01.10.10 18:21 
Hallo Leute,

ich glaube ich brauche mal wieder eine findigen. Und zwar möchte ich eine List<TreeNode> via DragDrop zwischen TreeViews verschieben. Mit einzelnen Nodes ist es kein Problem. Ich habe ein Problem beim casten der Liste im DragDrop-Event.

So erstelle ich die Liste:
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
void treeViewOpen_ItemDrag(object sender, ItemDragEventArgs e)
{
    List<TreeNode> listOfTreeNodes = new List<TreeNode>();
    foreach (TreeNode tn in treeViewOpenAnalysis.Nodes)
    {
        if (tn.Parent == null)//MainNode
        {
            if (tn.Checked)
                listOfTreeNodes.Add(tn);
        }
    }
    DoDragDrop(listOfTreeNodes, DragDropEffects.Move);
    //DoDragDrop(e.Item, DragDropEffects.Move);<---funktioniert
}

Vielen Dank schon mal!



ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
void treeViewData_DragDrop(object sender, DragEventArgs e)
{           
    List<TreeNode> listOfTreeNodes = e.Data.GetData("System.Collections.Generic.List<TreeNode>"as List<TreeNode>; <---hier hapert es 

    //TreeNode newSampleNode = e.Data.GetData("System.Windows.Forms.TreeNode") as TreeNode;<---funktioniert 
}

_________________
Gruß
Christoph
Kha
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3803
Erhaltene Danke: 176

Arch Linux
Python, C, C++ (vim)
BeitragVerfasst: Fr 01.10.10 19:50 
Warum benutzt du nicht die Überladung mit Type-Paremeter?

_________________
>λ=
Christoph1972 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 690
Erhaltene Danke: 16


VS2015 Pro / C# & VB.Net
BeitragVerfasst: Fr 01.10.10 20:31 
Jup, vielen Dank! Hatte ich zwar schon probiert, aber nichr gecastet, dachte das ist nicht nötig.....

ausblenden C#-Quelltext
1:
 List<TreeNode> listOfTreeNodes = e.Data.GetData(typeof(List<TreeNode>)) as List<TreeNode>;					

_________________
Gruß
Christoph
Kha
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3803
Erhaltene Danke: 176

Arch Linux
Python, C, C++ (vim)
BeitragVerfasst: Sa 02.10.10 00:39 
Tja, die Methode ist eben leider älter als Generics ;) .

_________________
>λ=
Christoph1972 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 690
Erhaltene Danke: 16


VS2015 Pro / C# & VB.Net
BeitragVerfasst: Sa 02.10.10 07:58 
Hätte ich trotzdem schneller selbst draufkommen können! Ich hatte aber auch meine schreiende Tocher auf dem Arm :zwinker:, da kann das schon mal vorkommen.

_________________
Gruß
Christoph