c# - TreeView not visually updating while right mouse dragging -
i have treeview control in have implemented drag , drop. there code in dragover handler highlight correct destination node dragged node, works fine. use left mouse button move node, , right button copy it. problem when using right button, treeview not displaying selected node during drag action. proper node being selected, have verified stop point, treeview not showing this. show when left mouse button being used.
private void documentmap_itemdrag(object sender, itemdrageventargs e) { // handle treenode objects if (e.item.gettype() != typeof(treenode)) return; this.dragnode = e.item treenode; var sourcetype = xmlitem.fromelement(this.dragnode.tag xelement).itemtype; if (sourcetype == xml.projectheader || sourcetype == xml.groupheader) return; switch (e.button) { case system.windows.forms.mousebuttons.left: dodragdrop(e.item, dragdropeffects.move); break; case system.windows.forms.mousebuttons.right: dodragdrop(e.item, dragdropeffects.copy); break; } this.dragnode = null; } private void documentmap_dragover(object sender, drageventargs e) { if (this.dragnode == null) return; var targettype = xmlitem.fromnode(this.dragnode.parent).itemtype; var hovernode = documentmap.getnodeat(documentmap.pointtoclient(new point(e.x, e.y))); var targetnode = findnodeinancestors(hovernode, targettype); if (targetnode != null && targetnode != this.dragnode.parent) documentmap.selectednode = targetnode; else documentmap.selectednode = null; }
i encountered problem myself , making native send message call force item selection worked me:
using system; using system.runtime.interopservices; using system.windows.forms; public static class nativeextensions { private const int tvm_selectitem = (0x1100 + 11); [dllimport("user32.dll", charset=charset.auto)] public static extern intptr sendmessage(handleref hwnd, int msg, intptr wparam, intptr lparam); /// <summary> /// forces selection of <see cref="system.windows.forms.treenode"/> using unsafe sendmessage call /// </summary> /// <param name="selectiontype">type of selection make</param> /// <exception cref="system.nullreferenceexception">this node null</exception> /// <exception cref="system.argumentexception">the handle node not created, node /// not have parent <see cref="system.windows.forms.treeview"/>, or handle node's parent <see cref="system.windows.forms.treeview"/> /// not created</exception> public static void forceselection(this treenode nodetoselect, unmanagedtreenodeselecttype selectiontype) { if (nodetoselect == null) throw new nullreferenceexception(); if (nodetoselect.handle == intptr.zero) throw new argumentexception("handle node not created"); if (nodetoselect.treeview == null) throw new argumentexception("node not have parent treeview."); if (nodetoselect.treeview.handle == intptr.zero) throw new argumentexception("handle node's parent treeview not created."); nodetoselect.treeview.selectednode = nodetoselect; sendmessage(new handleref(nodetoselect.treeview, nodetoselect.treeview.handle), tvm_selectitem, (intptr)selectiontype, nodetoselect.handle); } /// <summary> /// type of selection make when forcing <see cref="system.windows.forms.treenode"/> selection unmanaged code /// </summary> public enum unmanagedtreenodeselecttype { //documentation taken http://msdn.microsoft.com/en-us/library/31917zyz.aspx /// <summary> /// sets selection given item /// </summary> setselection = 0x0009, //tvgn_caret /// <summary> /// redraws given item in style used indicate target of drag-and-drop operation /// </summary> draganddroptarget = 0x0008, //tvgn_drophilite /// <summary> /// scrolls tree view vertically given item first visible item /// </summary> firstvisible = 0x0005, //tvgn_firstvisible } }
to use it:
targetnode.forceselection(nativeextensions.unmanagedtreenodeselecttype.draganddroptarget);
Comments
Post a Comment