From 20a3501553f7b2a738f37383dca462eb11d617c8 Mon Sep 17 00:00:00 2001 From: KB Bot Date: Wed, 7 Aug 2024 13:11:42 +0000 Subject: [PATCH 1/3] Added new kb article end-edit-on-cell-radgridview --- .../end-edit-on-cell-radgridview.md | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 knowledge-base/end-edit-on-cell-radgridview.md diff --git a/knowledge-base/end-edit-on-cell-radgridview.md b/knowledge-base/end-edit-on-cell-radgridview.md new file mode 100644 index 000000000..473519b00 --- /dev/null +++ b/knowledge-base/end-edit-on-cell-radgridview.md @@ -0,0 +1,68 @@ +--- +title: Ending Edit Mode When Navigating to Another Cell in RadGridView for WinForms +description: Learn how to configure RadGridView to end cell editing when the user navigates to another cell, similar to the standard DataGridView behavior. +type: how-to +page_title: How to End Editing on Cell Navigation in RadGridView for WinForms +slug: end-editing-on-cell-navigation-radgridview-winforms +tags: radgridview, winforms, celledit, cellnavigation, behavior +res_type: kb +ticketid: 1657423 +--- + +## Environment + +| Product | Version | +| --- | --- | +| RadGridView for WinForms | Current | + +## Description + +In RadGridView for WinForms, I want to end the edit mode of a cell when navigating to another cell, similar to the behavior seen in the standard DataGridView. Currently, calling `EndEdit` in the `CurrentCellChanged` event handler does not achieve this. Additionally, I want the `CellBeginEdit` event to fire for every new cell navigated to, ensuring that I can validate whether a user can edit a particular cell. + +This KB article also answers the following questions: +- How can I customize cell navigation behavior in RadGridView? +- How to end cell editing on cell change in RadGridView? +- How do I trigger `CellBeginEdit` for each cell in RadGridView? + +## Solution + +To achieve the desired behavior where cell editing ends upon navigating to another cell, and to ensure the `CellBeginEdit` event fires for each cell, you can customize the `GridRowBehavior` of RadGridView. This involves creating a custom `GridRowBehavior` and overriding the `OnMouseDownLeft` method. Additionally, for keyboard navigation, you can override other methods like `ProcessUpKey`. + +Here is a custom `GridDataRowBehavior` implementation: + +```csharp +public class CustomGridDataRowBehavior : GridDataRowBehavior +{ + protected override bool OnMouseDownLeft(MouseEventArgs e) + { + GridCellElement cellElement = this.GetCellAtPoint(e.Location); + if (cellElement != null) + { + this.GridViewElement.EditorManager.CloseEditor(); + } + + return base.OnMouseDownLeft(e); + } + + // Add similar overrides for keyboard navigation if necessary +} +``` + +To apply this custom behavior, register it with your RadGridView. This custom behavior closes the editor when navigating away from a cell, ensuring that the `CellBeginEdit` event can trigger for every new cell navigated to. + +```csharp +// Example of how to register the custom behavior +// gridView is your instance of RadGridView +gridView.GridBehavior = new CustomGridDataRowBehavior(); +``` + +Modify or extend this behavior as necessary to fit your specific requirements. + +## Notes + +- Customizing the `GridRowBehavior` provides flexibility in managing how user interactions with cells are handled. +- Remember to override additional methods if you wish to extend this behavior to keyboard navigation or other user actions. + +## See Also + +- [RadGridView for WinForms Documentation - Row Behaviors](https://docs.telerik.com/devtools/winforms/controls/gridview/rows/row-behaviors) From 7525dc7e1ae3e28a561801d6192e9d8c13861e95 Mon Sep 17 00:00:00 2001 From: Nadya Todorova <48494959+nade7o@users.noreply.github.com> Date: Wed, 7 Aug 2024 16:24:22 +0300 Subject: [PATCH 2/3] Update end-edit-on-cell-radgridview.md --- .../end-edit-on-cell-radgridview.md | 29 +++++-------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/knowledge-base/end-edit-on-cell-radgridview.md b/knowledge-base/end-edit-on-cell-radgridview.md index 473519b00..f14b5fe82 100644 --- a/knowledge-base/end-edit-on-cell-radgridview.md +++ b/knowledge-base/end-edit-on-cell-radgridview.md @@ -1,5 +1,5 @@ --- -title: Ending Edit Mode When Navigating to Another Cell in RadGridView for WinForms +title: End Edit Mode When Navigating to Another Cell in RadGridView for WinForms description: Learn how to configure RadGridView to end cell editing when the user navigates to another cell, similar to the standard DataGridView behavior. type: how-to page_title: How to End Editing on Cell Navigation in RadGridView for WinForms @@ -11,22 +11,17 @@ ticketid: 1657423 ## Environment -| Product | Version | -| --- | --- | -| RadGridView for WinForms | Current | +|Product Version|Product|Author| +|----|----|----| +|2024.2.514|RadGridView for WinForms|[Nadya Todorova](https://www.telerik.com/blogs/author/nadya-karaivanova)| ## Description -In RadGridView for WinForms, I want to end the edit mode of a cell when navigating to another cell, similar to the behavior seen in the standard DataGridView. Currently, calling `EndEdit` in the `CurrentCellChanged` event handler does not achieve this. Additionally, I want the `CellBeginEdit` event to fire for every new cell navigated to, ensuring that I can validate whether a user can edit a particular cell. - -This KB article also answers the following questions: -- How can I customize cell navigation behavior in RadGridView? -- How to end cell editing on cell change in RadGridView? -- How do I trigger `CellBeginEdit` for each cell in RadGridView? +By default, when RadGridView is in edit mode, and the user change the current cell, the new cell enters in edit mode automatically. In some cases, clients may want to change this behaviour and end the editing proccess once the user left the current cell. This behavior is represented in the MS DataGrid control. This article describes how one can achieve the same editing behavior as in MS DataGrid. ## Solution -To achieve the desired behavior where cell editing ends upon navigating to another cell, and to ensure the `CellBeginEdit` event fires for each cell, you can customize the `GridRowBehavior` of RadGridView. This involves creating a custom `GridRowBehavior` and overriding the `OnMouseDownLeft` method. Additionally, for keyboard navigation, you can override other methods like `ProcessUpKey`. +To achieve the desired behavior where cell editing ends upon navigating to another cell, you can customize the `GridRowBehavior` of RadGridView. This involves creating a custom `GridRowBehavior` and overriding the `OnMouseDownLeft` method. Here is a custom `GridDataRowBehavior` implementation: @@ -43,26 +38,16 @@ public class CustomGridDataRowBehavior : GridDataRowBehavior return base.OnMouseDownLeft(e); } - - // Add similar overrides for keyboard navigation if necessary } ``` -To apply this custom behavior, register it with your RadGridView. This custom behavior closes the editor when navigating away from a cell, ensuring that the `CellBeginEdit` event can trigger for every new cell navigated to. +To apply this custom behavior, register it with your RadGridView. This custom behavior closes the editor when navigating away from a cell. The `CellBeginEdit` event will trigger for every new cell the user navigates to. ```csharp // Example of how to register the custom behavior -// gridView is your instance of RadGridView gridView.GridBehavior = new CustomGridDataRowBehavior(); ``` -Modify or extend this behavior as necessary to fit your specific requirements. - -## Notes - -- Customizing the `GridRowBehavior` provides flexibility in managing how user interactions with cells are handled. -- Remember to override additional methods if you wish to extend this behavior to keyboard navigation or other user actions. - ## See Also - [RadGridView for WinForms Documentation - Row Behaviors](https://docs.telerik.com/devtools/winforms/controls/gridview/rows/row-behaviors) From 3d95c20c1eee96cf1846b94bdd3175f0b3060465 Mon Sep 17 00:00:00 2001 From: Dinko Krastev Date: Wed, 7 Aug 2024 16:28:50 +0300 Subject: [PATCH 3/3] Update end-edit-on-cell-radgridview.md --- knowledge-base/end-edit-on-cell-radgridview.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/knowledge-base/end-edit-on-cell-radgridview.md b/knowledge-base/end-edit-on-cell-radgridview.md index f14b5fe82..4c8a887ca 100644 --- a/knowledge-base/end-edit-on-cell-radgridview.md +++ b/knowledge-base/end-edit-on-cell-radgridview.md @@ -4,7 +4,7 @@ description: Learn how to configure RadGridView to end cell editing when the use type: how-to page_title: How to End Editing on Cell Navigation in RadGridView for WinForms slug: end-editing-on-cell-navigation-radgridview-winforms -tags: radgridview, winforms, celledit, cellnavigation, behavior +tags: gridview, winforms, celledit, cellnavigation, behavior res_type: kb ticketid: 1657423 --- @@ -17,7 +17,7 @@ ticketid: 1657423 ## Description -By default, when RadGridView is in edit mode, and the user change the current cell, the new cell enters in edit mode automatically. In some cases, clients may want to change this behaviour and end the editing proccess once the user left the current cell. This behavior is represented in the MS DataGrid control. This article describes how one can achieve the same editing behavior as in MS DataGrid. +By default, when RadGridView is in edit mode, and the user changes the current cell, the new cell enters in edit mode automatically. In some cases, clients may want to change this behavior and end the editing process once the user left the current cell. This behavior is represented in the MS DataGrid control. This article describes how one can achieve the same editing behavior as in MS DataGrid. ## Solution @@ -25,7 +25,7 @@ To achieve the desired behavior where cell editing ends upon navigating to anoth Here is a custom `GridDataRowBehavior` implementation: -```csharp +````C# public class CustomGridDataRowBehavior : GridDataRowBehavior { protected override bool OnMouseDownLeft(MouseEventArgs e) @@ -39,14 +39,14 @@ public class CustomGridDataRowBehavior : GridDataRowBehavior return base.OnMouseDownLeft(e); } } -``` +```` To apply this custom behavior, register it with your RadGridView. This custom behavior closes the editor when navigating away from a cell. The `CellBeginEdit` event will trigger for every new cell the user navigates to. -```csharp +````C# // Example of how to register the custom behavior gridView.GridBehavior = new CustomGridDataRowBehavior(); -``` +```` ## See Also