Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I listen for DragDataReceived in a TreeView when the Model is a TreeModelSort?
    primarykey
    data
    text
    <p>I have a TreeView whose Model is a TreeModelSort with a ListStore as its child. I would like this TreeView to listen to DragDataReceived. However, when I drag data to it, I get this warning:</p> <blockquote> <p>(TestDragDrop:4706): Gtk-WARNING **: You must override the default 'drag_drop' handler on GtkTreeView when using models that don't support the GtkTreeDragDest interface and enabling drag-and-drop. The simplest way to do this is to connect to 'drag_drop' and call g_signal_stop_emission_by_name() in your signal handler to prevent the default handler from running. Look at the source code for the default handler in gtktreeview.c to get an idea what your handler should do. (gtktreeview.c is in the GTK source code.) If you're using GTK from a language other than C, there may be a more natural way to override default handlers, e.g. via derivation.</p> </blockquote> <p>I'm a bit lost on how to do thisin Gtk#. The message says "If you're using GTK from a language other than C, there may be a more natural way to override default handlers, e.g. via derivation." Can someone point me to an example of what this would look like? What exactly am I overriding? There is no DragDrop method, and overriding OnDragDataReceived doesn't seem to work. Alternatively, I could manually sort the ListStore, but that seems like a really bad idea (especially since there doesn't seem to be any easy way to swap elements).</p> <p>Here is an example TreeView for reference:</p> <pre><code>using System; using System.Linq; using System.Text; using Gtk; namespace TestDragDrop { public class DestTreeView : TreeView { public DestTreeView () { ListStore store = new ListStore (typeof (string)); TreeModelSort sort = new TreeModelSort (store) { DefaultSortFunc = BarSortFunc }; Model = sort; TreeViewColumn column = new TreeViewColumn { Title = "Bar" }; CellRendererText cell = new CellRendererText (); column.PackStart (cell, true); column.SetCellDataFunc (cell, RenderBar); AppendColumn (column); EnableModelDragDest (Constants.Targets, Gdk.DragAction.Link); DragDataReceived += HandleDragDataReceived; store.AppendValues ("bar1"); store.AppendValues ("bar2"); } string GetValueAtPos (int x, int y) { TreePath path; TreeViewDropPosition pos; if (!GetDestRowAtPos (x, y, out path, out pos)) return ""; TreeIter iter; if (!Model.GetIter (out iter, path)) return ""; return (string) Model.GetValue (iter, 0); } void HandleDragDataReceived (object o, DragDataReceivedArgs args) { string text = System.Text.Encoding.UTF8.GetString (args.SelectionData.Data); string val = GetValueAtPos (args.X, args.Y); Console.WriteLine ("Data: '{0}'\nRow: '{1}'", text, val); } void RenderBar (TreeViewColumn column, CellRenderer renderer, TreeModel model, TreeIter iter) { ((CellRendererText) renderer).Text = (string) model.GetValue (iter, 0); } int BarSortFunc (TreeModel model, TreeIter iter1, TreeIter iter2) { string bar1 = (string) model.GetValue (iter1, 0); string bar2 = (string) model.GetValue (iter2, 0); return bar1.CompareTo (bar2); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload