Disallow column moves from one ColumnGroup to another

7 posts, 0 answers
  1. Myroslav
    Myroslav avatar
    3 posts
    Member since:
    Mar 2014

    Posted 07 Mar 2014 Link to this post

    We are using Telerik WPF contorls for the desktop application (2013 Q3 NET).

    We have few column groups in the grid and columns are sorted to them. We need to be able to prevent the user from moving the column from one ColumnGroup to the other. They should however be able to reorder columns as long as the column remains in the original ColumnGroup.

    Thank you!
  2. Nick
    Admin
    Nick avatar
    593 posts

    Posted 12 Mar 2014 Link to this post

    Hi Myroslav,

    You can try doing this by handling the DragOver event and set the Effects to none in case you don't want to drop a cell over the current target. 

    Hope this helps.

    Regards,
    Nik
    Telerik
     

    DevCraft Q1'14 is here! Watch the online conference to see how this release solves your top-5 .NET challenges. Watch on demand now.

     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Nils
    Nils avatar
    4 posts
    Member since:
    May 2015

    Posted 09 Mar in reply to Nick Link to this post

    Hi Nick,

    could you please provide a sample on how this can be achieved.

    Regards,

    Nils

  5. Nikolay
    Nikolay avatar
    3 posts
    Member since:
    Dec 2010

    Posted 11 Mar in reply to Nils Link to this post

    Hi Nils,

     

    The basic idea is to get the HeaderCell that you are dragging over, and compare its ColumnGroupName to the Dragged one. Should the names differ, set the DragEffects to none.

     

            private void OnGridViewDragOver(object sender, Telerik.Windows.DragDrop.DragEventArgs e)
            {
                var draggedCell = DragDropPayloadManager.GetDataFromObject(e.Data, "DraggedCell") as GridViewHeaderCell;
                var targetColumnHeader = e.OriginalSource as GridViewHeaderCell ?? (e.OriginalSource as FrameworkElement).ParentOfType<GridViewHeaderCell>();

                if(draggedCell != null && targetColumnHeader != null)
                {
                    if(draggedCell != null && !draggedCell.Column.ColumnGroupName.Equals(targetColumnHeader.Column.ColumnGroupName))
                    {
                        e.Effects = DragDropEffects.None;
                    }
                }
            }

     

    I am attaching a sample project demonstrating the approach as well. 

     

    Regards,

    Nick

  6. Nikolay
    Nikolay avatar
    3 posts
    Member since:
    Dec 2010

    Posted 11 Mar Link to this post

    Seems I can only attach image files.... 

    I changed the archive extension to .png. Just set it to .zip and everything should be fine. 

     

    Regards,

    Nick

  7. Nils
    Nils avatar
    4 posts
    Member since:
    May 2015

    Posted 11 Mar in reply to Nikolay Link to this post

    Hi Nick,

    Thanks for the sample.

    This seems to work, however only when ReorderColumnsMode is not set to "ReorderColumns".

    Regards

    Nils

  8. Nikolay
    Nikolay avatar
    3 posts
    Member since:
    Dec 2010

    Posted 11 Mar in reply to Nils Link to this post

    Hi, Nils,

     

    Absolutely correct. Setting the ReorderMode to ReorderColumns, pretty much makes this approach useless. Unfortunately, there isn't much you can do in that case, except canceling the reorder and restoring the previous state, if an invalid state has been achieved. 

     

Back to Top
UI for WPF is Visual Studio 2017 Ready