Skip to content

Commit bf21e87

Browse files
authored
Merge pull request #644 from telerik/new-kb-prevent-column-drag-over-pinned-radgridview-winforms-e15c72f0216146808edb804998f45c41
Added new kb article prevent-column-drag-over-pinned-radgridview-winforms
2 parents 42d89a7 + dd737e2 commit bf21e87

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
title: Prevent Column Dragging Over Pinned Columns in RadGridView for WinForms
3+
description: Learn how to restrict the reordering of RadGridView columns by preventing columns from being dragged over pinned columns.
4+
type: how-to
5+
page_title: How to Restrict Column Dragging Over Pinned Columns in RadGridView for WinForms
6+
slug: gridview-prevent-column-drag-over-pinned
7+
tags: gridview, winforms, drag-and-drop, pinned-columns, radgriddragdropservice
8+
res_type: kb
9+
ticketid: 1667283
10+
---
11+
12+
## Environment
13+
14+
|Product Version|Product|Author|
15+
|----|----|----|
16+
|2024.3.924|RadGridView for WinForms|[Nadya Todorova](https://www.telerik.com/blogs/author/nadya-karaivanova)|
17+
18+
## Description
19+
20+
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.
21+
22+
## Solution
23+
24+
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.
25+
26+
Follow these steps to implement the solution:
27+
28+
````C#
29+
// Access the RadDragDropService
30+
RadDragDropService svc = this.radGridView1.GridViewElement.GetService<RadDragDropService>();
31+
32+
// Subscribe to the PreviewDragOver event
33+
svc.PreviewDragOver += svc_PreviewDragOver;
34+
35+
// Event handler to prevent dropping over pinned columns
36+
private void svc_PreviewDragOver(object sender, RadDragOverEventArgs e)
37+
{
38+
if (e.HitTarget is GridHeaderCellElement)
39+
{
40+
GridHeaderCellElement headerCell = e.HitTarget as GridHeaderCellElement;
41+
if (headerCell.ColumnInfo.IsPinned)
42+
{
43+
// Prevent dropping over pinned columns
44+
e.CanDrop = false;
45+
}
46+
}
47+
}
48+
49+
````
50+
51+
## See Also
52+
53+
- [RadGridView for WinForms Documentation - Drag and Drop](https://docs.telerik.com/devtools/winforms/controls/gridview/drag-and-drop/radgridviewdragdropservice)
54+
- [RadGridView for WinForms Documentation - Pinned Columns](https://docs.telerik.com/devtools/winforms/controls/gridview/columns/pinned-columns)

0 commit comments

Comments
 (0)