View previous topic :: View next topic |
Author |
Message |
Aphadon
Joined: 16 Aug 2007 Posts: 9
|
Posted: Mon Aug 27, 2007 4:29 am Post subject: Problem with my DragDropListView |
|
|
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 |
|
|
Chris Miller
Joined: 27 Mar 2004 Posts: 514 Location: The Internet
|
Posted: Thu Sep 06, 2007 3:21 am Post subject: Re: Problem with my DragDropListView |
|
|
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 |
|
|
Aphadon
Joined: 16 Aug 2007 Posts: 9
|
Posted: Sat Sep 08, 2007 10:45 am Post subject: |
|
|
Ok, I will try it.. thanks for your reply! |
|
Back to top |
|
|
|