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.
6 Answers, 1 is accepted
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.
DevCraft Q1'14 is here! Watch the online conference to see how this release solves your top-5 .NET challenges. Watch on demand now.
could you please provide a sample on how this can be achieved.
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.
Thanks for the sample.
This seems to work, however only when ReorderColumnsMode is not set to "ReorderColumns".
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.