GridView - end edit on current cell changed

1 Answer 45 Views
GridView
Marian
Top achievements
Rank 2
Iron
Iron
Iron
Marian asked on 05 Jul 2024, 02:13 PM

Hello,

is it possible to end edit when user navigates to other cell? The same behavior as standard DataGridView:

I tried to call EndEdit in CurrentCellChanged event handler, but it doesn't work, probably there is something with current cell changing, nor IsInEditMode is not set in this event.

Marian
Top achievements
Rank 2
Iron
Iron
Iron
commented on 05 Jul 2024, 05:43 PM

One more comment, maybe this behavior could be ok for me, even if it's different to my previous projects, but I have one problem with this. I use CellBeginEdit event for validation, if user can edit some particular cell (because it's not possible to set ReadOnly on cell level), but with this behavior, CellBeginEdit is fired only for first cell, and after navigating to other cell, I don't have possibility to cancel edit. So alternative question, how can I solve this?

1 Answer, 1 is accepted

Sort by
0
Nadya | Tech Support Engineer
Telerik team
answered on 10 Jul 2024, 08:30 AM

Hello, Marian,

RadGridView manages user mouse and keyboard input over its rows by GridRowBehavior. You can customize the GridRowBehavior in a way that suits your requirements and your business needs. Please refer to the following article for more information and examples: Row behaviors - WinForms GridView Control - Telerik UI for WinForms

I prepared a custom GridRowBehavior which achieves the behavior that you want. The cell enters into edit mode when you click over a selected cell, when you change the selection, the cell ends editing. Now, RadGridView behaves similarly as MS DataGridView. As a result, the CellBeginEdit event triggers for the new cell as you expect. 

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);
    }
}

Do not forget to register this new behavior in your grid. Feel free to modify or extend this behavior if needed.

I hope this helps. If you have other questions, please let me know. 

Regards,
Nadya | Tech Support Engineer
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Marian
Top achievements
Rank 2
Iron
Iron
Iron
commented on 12 Jul 2024, 04:27 PM

Thanks, it works. I have added this also to ProcessUpKey etc for similar behavior also by arrow keys.
Tags
GridView
Asked by
Marian
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Nadya | Tech Support Engineer
Telerik team
Share this question
or