[Gtk-sharp-list] Newbie help wanted with drag and drop between listviews

alan battersby alan.battersby at ntlworld.com
Sat Jan 10 14:18:04 EST 2009


Hi,
I am using monodevelop.dock and have created two treeviews called
cellLib and latLib each in its own dockable window. I want to be able to
drag selected cells from cellLib and add them onto the selected  lattice
in  latLib. I thought that I had set the drag source and targets
correctly in my main window, but nothing seems to be happening as the
message is not displayed on the console so I assume the signal is not
being generated. Can anyone suggest what is going wrong?  See code
fragment below. I looked at the code example in TestDnD.cs for
inspiration. I do not really understand TargetTypes and so just used the
code from TestDnD.cs (which compiles and works ok). The treeview for
cellLib has two columns the first is a generated image, the second is a
string.

enum TargetType {
        String,
    };

    private static TargetEntry [] target_table = new TargetEntry [] {
        new TargetEntry ("STRING", 0, (uint) TargetType.String ),
        new TargetEntry ("text/plain", 0, (uint) TargetType.String),
    };
....
Now in MainWindow constructor after creating treeviews and adding to
DockItem etc.

// set up drag and drop targets
        Gtk.Drag.SourceSet (_cellLib,
                            Gdk.ModifierType.Button1Mask |
Gdk.ModifierType.Button3Mask,
                            target_table, Gdk.DragAction.Private );
        _cellLib.DragBegin += HandleDragBegin;
       
        Gtk.Drag.DestSet (_latlib, DestDefaults.All, target_table,
Gdk.DragAction.Private);
    }

    void HandleDragBegin(object o, DragBeginArgs args)
    {
        Console.WriteLine("Drag begin");
    }
   
Also I would like to transfer the cell object if possible not a string
so what would the target type be in that case?

Thanks
Alan


More information about the Gtk-sharp-list mailing list