Question

How can I prevent Windows (7/8) from scrolling (touch events?) an Infragistics UltraGrid when the user's left mouse button is down and moving? This behavior is messing up my dragdrop events.

I'm using an UltraGrid to receive and initiate dragdrops. When the user clicks an item in the grid I set a variable leftButton to true so I prevent dropping the item on itself. I'm using the MouseLeaveElement to start DoDragDrop the DragDrop from within the grid.

The code is below. It worked in Windows XP, but fails in Windows 7 and 8. mainGrid_MouseLeaveElement is now being called when the left mouse button is released and that's to late because that's when the drag should have finished. It looks like Windows OS is taking over when the left mouse is down and the mouse is being moved. It releases it back to the application when the mouse button is released.

private leftMouseDown = false;

public void Fill(ToolbarForm ownerForm, DocumentOwner owner, int? ownerIdentifier)
{
    ...
    this.mainGrid.DragDrop += new DragEventHandler(grid_DragDrop);
    this.mainGrid.DragEnter += new DragEventHandler(grid_DragEnter);
    this.mainGrid.MouseDown += new MouseEventHandler(mainGrid_MouseDown);
    this.mainGrid.MouseUp += new MouseEventHandler(mainGrid_MouseUp);
    this.mainGrid.MouseLeaveElement += new Infragistics.Win.UIElementEventHandler(mainGrid_MouseLeaveElement);
    ...
}

void mainGrid_MouseLeaveElement(object sender, Infragistics.Win.UIElementEventArgs e)
{
    if (leftMouseDown)
    {
        ...
        DataObject data = new DataObject();
        data.SetFileDropList(files);
        this.mainGrid.DoDragDrop(data, DragDropEffects.Copy);
        leftMouseDown = false;
    }
}

void mainGrid_MouseUp(object sender, MouseEventArgs e)
{
    if (e.Button == System.Windows.Forms.MouseButtons.Left)
        leftMouseDown = false;
}

void mainGrid_MouseDown(object sender, MouseEventArgs e)
{
    if (e.Button == System.Windows.Forms.MouseButtons.Left)
        leftMouseDown = true;
}

public void grid_DragDrop(object sender, DragEventArgs e)
{
    string[] filenames = (string[])e.Data.GetData(DataFormats.FileDrop);

    foreach (string filename in filenames)
    {
        this.AddDocument(filename);
    }
}

private void grid_DragEnter(object sender, DragEventArgs e)
{
    if (e.Data.GetDataPresent(DataFormats.FileDrop, false) && !leftMouseDown)
    {
        e.Effect = DragDropEffects.All;
    }

    else e.Effect = DragDropEffects.None;
}
Was it helpful?

Solution

Solved this problem by using the SelectionDrag event on the maingrid instead of MouseLeaveElement.

void maingrid_SelectionDrag(object sender, Infragistics.Win.UIElementEventArgs e)
{
    if (leftMouseDown)
    {
        ...
        DataObject data = new DataObject();
        data.SetFileDropList(files);
        this.mainGrid.DoDragDrop(data, DragDropEffects.Copy);
        leftMouseDown = false;
    }
}

instead of

void mainGrid_MouseLeaveElement(object sender, Infragistics.Win.UIElementEventArgs e)
{
    if (leftMouseDown)
    {
        ...
        DataObject data = new DataObject();
        data.SetFileDropList(files);
        this.mainGrid.DoDragDrop(data, DragDropEffects.Copy);
        leftMouseDown = false;
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top