Skip to content

Commit e1e9a96

Browse files
authored
Update prevent-column-drag-over-pinned-radgridview-winforms.md
1 parent 364d97e commit e1e9a96

File tree

1 file changed

+8
-25
lines changed

1 file changed

+8
-25
lines changed

knowledge-base/prevent-column-drag-over-pinned-radgridview-winforms.md

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
2-
title: Preventing Column Dragging Over Pinned Columns in RadGridView for WinForms
3-
description: Learn how to restrict the reordering of RadGridView columns in WinForms by preventing columns from being dragged over pinned columns.
2+
title: Prevent Column Dragging Over Pinned Columns in RadGridView for WinForms
3+
description: Learn how to restrict reordering of RadGridView columns by preventing columns from being dragged over pinned columns.
44
type: how-to
55
page_title: How to Restrict Column Dragging Over Pinned Columns in RadGridView for WinForms
66
slug: prevent-column-drag-over-pinned-radgridview-winforms
@@ -11,37 +11,21 @@ ticketid: 1667283
1111

1212
## Environment
1313

14-
<table>
15-
<tbody>
16-
<tr>
17-
<td>Product</td>
18-
<td>RadGridView for WinForms</td>
19-
</tr>
20-
</tbody>
21-
</table>
14+
|Product Version|Product|Author|
15+
|----|----|----|
16+
|2024.3.924|RadGridView for WinForms|[Nadya Karaivanova](https://www.telerik.com/blogs/author/nadya-karaivanova)|
2217

2318
## Description
2419

25-
When working with pinned columns in RadGridView, I want to prevent the user from dragging unpinned columns over or between the pinned columns. This issue arises when the first two columns are pinned, but an unpinned column can still be moved to the leftmost position or between pinned columns, effectively increasing the number of pinned columns.
26-
27-
This KB article also answers the following questions:
28-
- How can I restrict column reordering in RadGridView with pinned columns?
29-
- Is it possible to disable dragging columns over pinned columns in RadGridView for WinForms?
30-
- What method can prevent a column from being moved over pinned columns in RadGridView?
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 to the leftmost position or between pinned columns, effectively increasing the number of pinned columns.
3121

3222
## Solution
3323

3424
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.
3525

3626
Follow these steps to implement the solution:
3727

38-
1. Access the `RadDragDropService` from your `RadGridView` instance.
39-
2. Subscribe to the `PreviewDragOver` event of the `RadDragDropService`.
40-
3. In the event handler, check if the target of the drag operation is a pinned column. If so, set `e.CanDrop` to `false` to prevent the drop.
41-
42-
Here is a code snippet illustrating the process:
43-
44-
```csharp
28+
````C#
4529
// Access the RadDragDropService
4630
RadDragDropService svc = this.radGridView1.GridViewElement.GetService<RadDragDropService>();
4731

@@ -61,9 +45,8 @@ private void svc_PreviewDragOver(object sender, RadDragOverEventArgs e)
6145
}
6246
}
6347
}
64-
```
6548

66-
By implementing this solution, you ensure that users cannot drag unpinned columns over or between pinned columns, maintaining the integrity of your column layout in RadGridView.
49+
````
6750

6851
## See Also
6952

0 commit comments

Comments
 (0)