c# - How to create a panel with support for Drag and Drop? -


suppose have listbox custom elements , blank panel . when drag these items panel , must build on logic. example, if there's nothing panel , element located in middle. if there , new element stay near element closest . such possible implement?

for example:

enter image description here

i modified this answer of working drag , drop implementation adding sorting logic. placing item in middle visually can done css styling.

assumption: "closest it" means closest alphabetically.

public object lb_item = null;  private void listbox1_dragleave(object sender, eventargs e) {     listbox lb = sender listbox;      lb_item = lb.selecteditem;     lb.items.remove(lb.selecteditem); }  private void listbox1_dragenter(object sender, drageventargs e) {            if (lb_item != null)     {         listbox1.items.add(lb_item);         lb_item = null;          // here added logic:         // sort items added          // (thereby placing item in middle).         listbox1.sorted = true;     } }   private void listbox1_mousedown(object sender, mouseeventargs e) {     lb_item = null;      if (listbox1.items.count == 0)     {         return;     }                      int index = listbox1.indexfrompoint(e.x, e.y);     string s = listbox1.items[index].tostring();     dragdropeffects dde1 = dodragdrop(s, dragdropeffects.all);       }  private void form1_dragdrop(object sender, drageventargs e) {                 lb_item = null; } 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -