Declined
Last Updated: 19 Nov 2021 09:52 by ADMIN
dev
Created on: 07 Aug 2020 14:57
Category: GridView
Type: Bug Report
1
RadGridView: Exit edit Mode when GridView loses focus

Hi,

I have a question regarding RadGridView. When I edit a cell in GridView and then click on a button (outside of gridview) immediately (i.e I don't click on another cell to exit edit mode), the Gridview is still edit mode. Please refer to the short video named "Without Using EndEdit()" to easily understand my point here.

In order to exit the edit mode, I try the following code:

    Private Sub CustomGridView_LostFocus(sender As Object, e As EventArgs) Handles Me.LostFocus
        Me.EndEdit()
    End Sub

With this code, the gridview does exit the edit mode when I click on another button. But there is a problem with this method is that afterwards, I cannot edit the cell anymore.  Please refer to the short video named "Using EndEdit()" to better understand the problem.

So my question here is, is there any way that I can exit edit mode when clicking on another button right after editing a cell?

Thank you for your help.

Best regards,

Tran

 

 
4 comments
ADMIN
Dess | Tech Support Engineer, Principal
Posted on: 19 Nov 2021 09:52
Hello, 

I have prepared a sample code snippet for your reference:
        DataTable masterTable = new DataTable();
        DataTable childTable = new DataTable();

        public RadForm1()
        {
            InitializeComponent();

            masterTable.Columns.Add("Id", typeof(int));
            masterTable.Columns.Add("Name", typeof(string));
            for (int i = 0; i < 3; i++)
            {
                masterTable.Rows.Add(i, "Row" + i);
            }
            childTable.Columns.Add("Id", typeof(int));
            childTable.Columns.Add("ParentId", typeof(int));
            childTable.Columns.Add("Title", typeof(string));
            childTable.Columns.Add("Date", typeof(DateTime));
            Random rand = new Random();
            for (int i = 0; i < 20; i++)
            {
                childTable.Rows.Add(i, rand.Next(0, 3), "Child" + i, DateTime.Now.AddDays(i));
            }

            radGridView1.DataSource = masterTable;
            radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;

            GridViewTemplate template = new GridViewTemplate();
            template.DataSource = childTable;
            template.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
            radGridView1.MasterTemplate.Templates.Add(template);

            GridViewRelation relation = new GridViewRelation(radGridView1.MasterTemplate);
            relation.ChildTemplate = template;
            relation.RelationName = "MasterChild";
            relation.ParentColumnNames.Add("Id");
            relation.ChildColumnNames.Add("ParentId");
            radGridView1.Relations.Add(relation);

            this.radGridView1.UserAddedRow+=radGridView1_UserAddedRow; 
        } 

        private void radGridView1_UserAddedRow(object sender, GridViewRowEventArgs e)
        {
            e.Row.IsExpanded = true;
            this.radGridView1.CurrentRow = ((GridViewHierarchyRowInfo)e.Row).Views[0].TableAddNewRow;
            this.radGridView1.CurrentColumn = this.radGridView1.MasterTemplate.Templates[0].Columns[0];
            this.radGridView1.BeginEdit(); 
        }
I would like to note that it is a feedback portal item for reporting feature requests and bug reports. In case you have any further inquiries, I would kindly ask you to open a separate ticket with the appropriate Product (RadGridView for WinForms) from your Telerik account or ask the community for help:
https://www.telerik.com/forums/winforms 

Thank you for your understanding.

Regards,
Dess | Tech Support Engineer, Principal
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.

Bidder
Posted on: 16 Nov 2021 05:26

Hi.

I have two gridviews in a form: Master and Detail. I am trying to set the focus on Detail Grid when the Master grid UserAddedRow Event occurs, but, it doesn't work. The focus always stays in the Master grid. Is possible to do that in Telerik GridView?

ADMIN
Dimitar
Posted on: 17 Aug 2020 14:27

By default EndEdit is fired from the Validation event. RadRibbonBar doesn't cause validation by default and you can change this behavior by manually setting radRibbonBar.CausesValidation to true

For reference: the MS DataGridView behaves the same way. 

ADMIN
Dess | Tech Support Engineer, Principal
Posted on: 10 Aug 2020 05:11
Hello, Tran,

Indeed, the illustrated behavior doesn't seem to be correct. I would like to note that the RadGridView.LostFocus event is also fired when the editor is activated since it gains the focus. Hence, it is not the appropriate place for calling EndEdit. Following the provided information, I was able to observe identical behavior on my end. Please refer to the attached gif file.

I have logged it in our feedback portal by creating a public thread on your behalf. You can track its progress, subscribe for status changes and add your comments on the following link - feedback item.

I have also updated your Telerik points.

Currently, the possible solution that I can suggest is to call the EndEdit method in the Click event of the RadButtonElement in the ribbon: 

    Private Sub RadButtonElement1_Click(sender As Object, e As EventArgs)
        Me.RadGridView1.EndEdit()
    End Sub

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik