Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new kb article prevent-column-drag-over-pinned-radgridview-winforms #644

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
title: Prevent Column Dragging Over Pinned Columns in RadGridView for WinForms
description: Learn how to restrict reordering of RadGridView columns by preventing columns from being dragged over pinned columns.
type: how-to
page_title: How to Restrict Column Dragging Over Pinned Columns in RadGridView for WinForms
slug: prevent-column-drag-over-pinned-radgridview-winforms
tags: radgridview, winforms, drag-and-drop, pinned-columns, radgriddragdropservice
res_type: kb
ticketid: 1667283
---

## Environment

|Product Version|Product|Author|
|----|----|----|
|2024.3.924|RadGridView for WinForms|[Nadya Todorova](https://www.telerik.com/blogs/author/nadya-karaivanova)|

## Description

When working with pinned columns in RadGridView, the client may want to prevent dragging unpinned columns over or between the pinned columns. Currently unpinned column can be moved and placed between pinned columns, effectively increasing the number of pinned columns.

## Solution

To achieve the desired behavior, leverage the [RadDragDropService](https://docs.telerik.com/devtools/winforms/controls/gridview/drag-and-drop/radgridviewdragdropservice) of RadGridView, which handles the drag-and-drop operations. By handling the `PreviewDragOver` event, you can prevent a column from being dropped over a pinned column.

Follow these steps to implement the solution:

````C#
// Access the RadDragDropService
RadDragDropService svc = this.radGridView1.GridViewElement.GetService<RadDragDropService>();

// Subscribe to the PreviewDragOver event
svc.PreviewDragOver += svc_PreviewDragOver;

// Event handler to prevent dropping over pinned columns
private void svc_PreviewDragOver(object sender, RadDragOverEventArgs e)
{
if (e.HitTarget is GridHeaderCellElement)
{
GridHeaderCellElement headerCell = e.HitTarget as GridHeaderCellElement;
if (headerCell.ColumnInfo.IsPinned)
{
// Prevent dropping over pinned columns
e.CanDrop = false;
}
}
}

````

## See Also

- [RadGridView for WinForms Documentation - Drag and Drop](https://docs.telerik.com/devtools/winforms/controls/gridview/drag-and-drop/radgridviewdragdropservice)
- [RadGridView for WinForms Documentation - Pinned Columns](https://docs.telerik.com/devtools/winforms/controls/gridview/columns/pinned-columns)