Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1500
Column drag&drop. Reset column headers on unsuccessful drag
posted

Hi,

 I'm using the grid in RowLayout mode. When I drag the column header, in the DragOver event handler I check if the column header can be dropped at the current position and set an appropriate effect from DragDropEffects enum.

When I stop dragging in an invalid position (and DragDropEffect.None effect is active) the column header that has been dragging stays at the position where I left it - just hanging over the grid.

What should I do to remove that hanging column header?

Thanks,

Vitaly 

  • 467470
    Verified Answer
    Offline posted

     Hi Vitaly,

        I don't understand. Are you saying that you are trying to implement the dragging and dropping of columns manually? If that's the case, then the column header you are dragging must be provided by you, so I couldn't tell you how to remove it.

        If you are using the grid's built-in drag and drop functionality, then the DragOver event would not even fire when you are dragging a column header, so you could not change the Effects - the grid would handle everything.  

  • 5
    posted

    Hi,

      I've discovered the same issue. My application uses drag modifier (the Alt key). When key is pressed, user can swap columns. Otherwise, standard drag operation occurs, allowing to drag columns to other controls. The code is as follows:

      private void
          mygrid_SelectionDrag(object sender, System.ComponentModel.CancelEventArgs e)
    {

     bool ingrid = !(Helpers.GetAsyncKeyState(0x12) == 0); // is Alt pressed?

         if (!ingrid)
          {
            gridLinia.DisplayLayout.Override.AllowColMoving = AllowColMoving.NotAllowed;
            gridLinia.DoDragDrop(gridLinia.Selected.Columns, DragDropEffects.Move);
          }
          else
            gridLinia.DisplayLayout.Override.AllowColMoving = AllowColMoving.Default;

    }

    It took some time to figure it out, but looks like it works as I wanted to.

    Regards,

    E.Butusov