This is a migrated thread and some comments may be shown as answers.

Disallow column moves from one ColumnGroup to another

6 Answers 58 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Myroslav
Top achievements
Rank 1
Myroslav asked on 07 Mar 2014, 09:55 PM
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!

6 Answers, 1 is accepted

Sort by
0
Nick
Telerik team
answered on 12 Mar 2014, 12:40 PM
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.

 
0
Nils
Top achievements
Rank 1
answered on 09 Mar 2016, 10:53 AM

Hi Nick,

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

Regards,

Nils

0
Nikolay
Top achievements
Rank 1
answered on 11 Mar 2016, 09:08 AM

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

0
Nikolay
Top achievements
Rank 1
answered on 11 Mar 2016, 09:12 AM

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

0
Nils
Top achievements
Rank 1
answered on 11 Mar 2016, 10:02 AM

Hi Nick,

Thanks for the sample.

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

Regards

Nils

0
Nikolay
Top achievements
Rank 1
answered on 11 Mar 2016, 11:07 AM

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. 

 

Tags
GridView
Asked by
Myroslav
Top achievements
Rank 1
Answers by
Nick
Telerik team
Nils
Top achievements
Rank 1
Nikolay
Top achievements
Rank 1
Share this question
or