FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Problem with my DragDropListView

 
Post new topic   Reply to topic     Forum Index -> DFL
View previous topic :: View next topic  
Author Message
Aphadon



Joined: 16 Aug 2007
Posts: 9

PostPosted: Mon Aug 27, 2007 4:29 am    Post subject: Problem with my DragDropListView Reply with quote

Hello,

I have a problem with my ListView which I try to "teach" drag&drop.
I almost copied the code from the ListBox example and it seems to work but when I do a simple click on an item the program starts a drag&drop action.
The cursor changes and I see the info in the title on the main form which I set in the onDragOver function.

Does someone have the same problem? I really don't know what to do ...

private variables I use in MyListView class
Code:

private int dragIndex;
private int overIndex;
private int dropIndex;


and here the drag&drop functions (I wrote my own indexFromPoint, insertionIndexFromPoint and getSelected functions)
Code:

   protected override void onMouseDown(MouseEventArgs mea)
   {
      super.onMouseDown(mea);
      
      if (mea.button & MouseButtons.LEFT)
      {
         /+int+/ dragIndex/+selindex+/ = indexFromPoint(Point(mea.x, mea.y));
         if ((dragIndex/+selindex+/ != -1) && getSelected(dragIndex/+selindex+/))
         {
            DataObject dobj = new DataObject;
            dobj.setData(DataFormats.utf8, Data(items[dragIndex/+selindex+/].toString()));
            
            DragDropEffects dropresult = DragDropEffects.NONE;
            try
            {
               dropIndex = int.max;
               dropresult = doDragDrop(dobj, DragDropEffects.MOVE | DragDropEffects.COPY);
            }
            catch
            {
            }
            
            if (dropresult & DragDropEffects.MOVE)
            {
               if (dropIndex <= dragIndex/+selindex+/)
                  dragIndex/+selindex+/++;
               items.removeAt(dragIndex/+selindex+/);
            }
         }
      }
   }
   
   protected override void onDragOver(DragEventArgs dea)
   {
      super.onDragOver(dea);
      
      if (dea.data.getDataPresent(DataFormats.utf8))
      {
         int overIndex = insertionIndexFromPoint(pointToClient(Point(dea.x, dea.y)));
         if (overIndex != -1)
         {
            dea.effect = dea.allowedEffect & DragDropEffects.MOVE;
            
            // show some test info...
            parent.text = "onDragOver ... will insert at index: " ~
               std.string.toString(overIndex);
         }
      }
   }
   
   protected override void onDragDrop(DragEventArgs dea)
   {
      super.onDragDrop(dea);
      
      if (dea.data.getDataPresent(DataFormats.utf8))
      {
         // still have to change the following
         
         char[] liststring = dea.data.getData(DataFormats.utf8).getString();
         
         int i = insertionIndexFromPoint(pointToClient(Point(dea.x, dea.y)));
         
         items.insert(i, liststring);
         items[i].selected = true;//selectedIndex = i;
         dropIndex = i;
         
         dea.effect = dea.allowedEffect & DragDropEffects.MOVE;
      }
   }
Back to top
View user's profile Send private message
Chris Miller



Joined: 27 Mar 2004
Posts: 514
Location: The Internet

PostPosted: Thu Sep 06, 2007 3:21 am    Post subject: Re: Problem with my DragDropListView Reply with quote

What if you start the drag action in onMouseMove (also checking for left button)? You would need to have a flag that keeps track of the drag state; dragging = true in this case only if !dragging, dragging = false on mouse up.
Back to top
View user's profile Send private message
Aphadon



Joined: 16 Aug 2007
Posts: 9

PostPosted: Sat Sep 08, 2007 10:45 am    Post subject: Reply with quote

Ok, I will try it.. thanks for your reply!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> DFL All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group