|
| 1 | +--- |
| 2 | +title: End Edit Mode When Navigating to Another Cell in RadGridView for WinForms |
| 3 | +description: Learn how to configure RadGridView to end cell editing when the user navigates to another cell, similar to the standard DataGridView behavior. |
| 4 | +type: how-to |
| 5 | +page_title: How to End Editing on Cell Navigation in RadGridView for WinForms |
| 6 | +slug: end-editing-on-cell-navigation-radgridview-winforms |
| 7 | +tags: gridview, winforms, celledit, cellnavigation, behavior |
| 8 | +res_type: kb |
| 9 | +ticketid: 1657423 |
| 10 | +--- |
| 11 | + |
| 12 | +## Environment |
| 13 | + |
| 14 | +|Product Version|Product|Author| |
| 15 | +|----|----|----| |
| 16 | +|2024.2.514|RadGridView for WinForms|[Nadya Todorova](https://www.telerik.com/blogs/author/nadya-karaivanova)| |
| 17 | + |
| 18 | +## Description |
| 19 | + |
| 20 | +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. |
| 21 | + |
| 22 | +## Solution |
| 23 | + |
| 24 | +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. |
| 25 | + |
| 26 | +Here is a custom `GridDataRowBehavior` implementation: |
| 27 | + |
| 28 | +````C# |
| 29 | +public class CustomGridDataRowBehavior : GridDataRowBehavior |
| 30 | +{ |
| 31 | + protected override bool OnMouseDownLeft(MouseEventArgs e) |
| 32 | + { |
| 33 | + GridCellElement cellElement = this.GetCellAtPoint(e.Location); |
| 34 | + if (cellElement != null) |
| 35 | + { |
| 36 | + this.GridViewElement.EditorManager.CloseEditor(); |
| 37 | + } |
| 38 | + |
| 39 | + return base.OnMouseDownLeft(e); |
| 40 | + } |
| 41 | +} |
| 42 | +```` |
| 43 | + |
| 44 | +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. |
| 45 | + |
| 46 | +````C# |
| 47 | +// Example of how to register the custom behavior |
| 48 | +gridView.GridBehavior = new CustomGridDataRowBehavior(); |
| 49 | +```` |
| 50 | + |
| 51 | +## See Also |
| 52 | + |
| 53 | +- [RadGridView for WinForms Documentation - Row Behaviors](https://docs.telerik.com/devtools/winforms/controls/gridview/rows/row-behaviors) |
0 commit comments