From 364d97e2349d5f75fb19c42c6edc1f45df4d31de Mon Sep 17 00:00:00 2001 From: KB Bot Date: Tue, 15 Oct 2024 13:58:59 +0000 Subject: [PATCH 1/3] Added new kb article prevent-column-drag-over-pinned-radgridview-winforms --- ...n-drag-over-pinned-radgridview-winforms.md | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 knowledge-base/prevent-column-drag-over-pinned-radgridview-winforms.md diff --git a/knowledge-base/prevent-column-drag-over-pinned-radgridview-winforms.md b/knowledge-base/prevent-column-drag-over-pinned-radgridview-winforms.md new file mode 100644 index 000000000..9ea05a08c --- /dev/null +++ b/knowledge-base/prevent-column-drag-over-pinned-radgridview-winforms.md @@ -0,0 +1,71 @@ +--- +title: Preventing Column Dragging Over Pinned Columns in RadGridView for WinForms +description: Learn how to restrict the reordering of RadGridView columns in WinForms 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 + + + + + + + + +
ProductRadGridView for WinForms
+ +## Description + +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. + +This KB article also answers the following questions: +- How can I restrict column reordering in RadGridView with pinned columns? +- Is it possible to disable dragging columns over pinned columns in RadGridView for WinForms? +- What method can prevent a column from being moved over pinned columns in RadGridView? + +## 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: + +1. Access the `RadDragDropService` from your `RadGridView` instance. +2. Subscribe to the `PreviewDragOver` event of the `RadDragDropService`. +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. + +Here is a code snippet illustrating the process: + +```csharp +// Access the RadDragDropService +RadDragDropService svc = this.radGridView1.GridViewElement.GetService(); + +// 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; + } + } +} +``` + +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. + +## 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) From e1e9a96c3cf24fb3ed5152ef68061475e66f013f Mon Sep 17 00:00:00 2001 From: Nadya Todorova <48494959+nade7o@users.noreply.github.com> Date: Tue, 15 Oct 2024 17:06:52 +0300 Subject: [PATCH 2/3] Update prevent-column-drag-over-pinned-radgridview-winforms.md --- ...n-drag-over-pinned-radgridview-winforms.md | 33 +++++-------------- 1 file changed, 8 insertions(+), 25 deletions(-) diff --git a/knowledge-base/prevent-column-drag-over-pinned-radgridview-winforms.md b/knowledge-base/prevent-column-drag-over-pinned-radgridview-winforms.md index 9ea05a08c..0d7d37cc7 100644 --- a/knowledge-base/prevent-column-drag-over-pinned-radgridview-winforms.md +++ b/knowledge-base/prevent-column-drag-over-pinned-radgridview-winforms.md @@ -1,6 +1,6 @@ --- -title: Preventing Column Dragging Over Pinned Columns in RadGridView for WinForms -description: Learn how to restrict the reordering of RadGridView columns in WinForms by preventing columns from being dragged over pinned columns. +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 @@ -11,23 +11,13 @@ ticketid: 1667283 ## Environment - - - - - - - -
ProductRadGridView for WinForms
+|Product Version|Product|Author| +|----|----|----| +|2024.3.924|RadGridView for WinForms|[Nadya Karaivanova](https://www.telerik.com/blogs/author/nadya-karaivanova)| ## Description -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. - -This KB article also answers the following questions: -- How can I restrict column reordering in RadGridView with pinned columns? -- Is it possible to disable dragging columns over pinned columns in RadGridView for WinForms? -- What method can prevent a column from being moved over pinned columns in RadGridView? +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. ## Solution @@ -35,13 +25,7 @@ To achieve the desired behavior, leverage the [RadDragDropService](https://docs. Follow these steps to implement the solution: -1. Access the `RadDragDropService` from your `RadGridView` instance. -2. Subscribe to the `PreviewDragOver` event of the `RadDragDropService`. -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. - -Here is a code snippet illustrating the process: - -```csharp +````C# // Access the RadDragDropService RadDragDropService svc = this.radGridView1.GridViewElement.GetService(); @@ -61,9 +45,8 @@ private void svc_PreviewDragOver(object sender, RadDragOverEventArgs e) } } } -``` -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. +```` ## See Also From ec3a01010e2374edd6aace23ccee44ad48f34d6d Mon Sep 17 00:00:00 2001 From: Nadya Todorova <48494959+nade7o@users.noreply.github.com> Date: Tue, 15 Oct 2024 17:09:55 +0300 Subject: [PATCH 3/3] Update prevent-column-drag-over-pinned-radgridview-winforms.md --- .../prevent-column-drag-over-pinned-radgridview-winforms.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/knowledge-base/prevent-column-drag-over-pinned-radgridview-winforms.md b/knowledge-base/prevent-column-drag-over-pinned-radgridview-winforms.md index 0d7d37cc7..3543360c6 100644 --- a/knowledge-base/prevent-column-drag-over-pinned-radgridview-winforms.md +++ b/knowledge-base/prevent-column-drag-over-pinned-radgridview-winforms.md @@ -13,11 +13,11 @@ ticketid: 1667283 |Product Version|Product|Author| |----|----|----| -|2024.3.924|RadGridView for WinForms|[Nadya Karaivanova](https://www.telerik.com/blogs/author/nadya-karaivanova)| +|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 to the leftmost position or between pinned columns, effectively increasing the number of pinned columns. +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