This is a migrated thread and some comments may be shown as answers.

GridView CellEndEdit Add New Row

11 Answers 606 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Paidakal
Top achievements
Rank 1
Paidakal asked on 06 Apr 2017, 08:07 AM

Hi

How I have to add new row on cell end edit. I have 10 columns in the gridview, after particular cell end edit and pressing tab key i should add a new row.

I tried ProcessTab Key and it is not working.

Please let me know how i can achieve this.

Thanks in advance.

Regards

Gopinath

 

 

 

 

 

11 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 06 Apr 2017, 10:51 AM
Hello , 

Thank you for writing.  

RadGridView has an editing mechanism and only one cell can be in edit mode at a time. Additional information about editing in RadGridView is available here: http://docs.telerik.com/devtools/winforms/gridview/editors/editors

RadGridView manages user mouse and keyboard input over its rows by GridRowBehavior. Depending on the row type, RadGridView introduces different behaviors. Thus, you can achieve some custom behavior when pressing the Tab key considering the row type. You can refer to the following help article: http://docs.telerik.com/devtools/winforms/gridview/rows/row-behaviors

I hope this information helps. Should you have further questions I would be glad to help.

Regards,
Dess
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Gopinath
Top achievements
Rank 1
answered on 06 Apr 2017, 11:35 AM

Hi,

Thanks for the reply.

I tried working with Row behavior, i am unable to get new row after the rate column. and the focus should be supplier name in newly added Row.

Pl find the attached images.

I tried with the following Code.

 public class MyGridBehavior : Telerik.WinControls.UI.GridNewRowBehavior
        {
            protected override bool ProcessTabKey(KeyEventArgs keys)
            {
                if (this.GridControl.CurrentCell.ColumnIndex == this.GridControl.Columns.Count - 1 && this.GridControl.CurrentCell.RowIndex == this.GridControl.Rows.Count - 1)
                {
                    this.GridControl.Rows.AddNew();
                    return true;
                }

                return base.ProcessTabKey(keys);
            }
        }

 BaseGridBehavior gridBehavior = gvProductSupplier.GridBehavior as BaseGridBehavior;
            gridBehavior.UnregisterBehavior(typeof(GridViewNewRowInfo));
            gridBehavior.RegisterBehavior(typeof(GridViewNewRowInfo), new MyGridBehavior());

Regards

Gopinath

 

 

 

0
Gopinath
Top achievements
Rank 1
answered on 06 Apr 2017, 11:45 AM

Hi Dess,

Sorry to trouble u again.

Pl if u have any sample code on GridNewRowBehavior, pl forward it.

I need that i have to insert a new row after the Rate and continue my data entry process. 

Regards

Gopinath

 

0
Gopinath
Top achievements
Rank 1
answered on 07 Apr 2017, 06:24 AM

Hi Dess,

I tried many ways, I am using unbound grid. I tried GridNewRow. row is not added.

Following code i tried

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.IO;
using System.Drawing;
using System.Text;
using System.Collections;
using System.Windows.Forms;
using Telerik.WinControls;
using Telerik.WinControls.UI;
using Telerik.WinControls.Data;

namespace Oet.Rcv3.Ent.Frms
{
    public partial class TestNewRowBehavior : Telerik.WinControls.UI.RadForm
    {
        public TestNewRowBehavior()
        {
            InitializeComponent();
        }

        private void TestNewRowBehavior_Load(object sender, EventArgs e)
        {
            radGridView1.AllowAddNewRow = false;
            radGridView1.AddNewRowPosition = SystemRowPosition.Bottom;
            radGridView1.Rows.AddNew();

            BaseGridBehavior gridBehavior = radGridView1.GridBehavior as BaseGridBehavior;
            gridBehavior.UnregisterBehavior(typeof(GridViewNewRowInfo));
            gridBehavior.RegisterBehavior(typeof(GridViewNewRowInfo), new MyGridBehavior());

            radGridView1.Columns["Column1"].IsCurrent = true;
            radGridView1.BeginEdit();

        }

        public class MyGridBehavior : Telerik.WinControls.UI.GridNewRowBehavior
        {
            protected override bool ProcessTabKey(KeyEventArgs keys)
            {
                if (this.GridControl.CurrentCell.ColumnIndex == this.GridControl.Columns.Count - 1 && this.GridControl.CurrentCell.RowIndex == this.GridControl.Rows.Count - 1)
                {
                    this.GridControl.Rows.AddNew();
                    return true;
                }

                return base.ProcessTabKey(keys);
            }
        }
    }
}

Regards

Gopinath

 

 

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 07 Apr 2017, 08:20 AM
Hello Gopinath, 

Thank you for writing back. 

According to the provided sample code, it seems that you set the AllowAddNewRow property to false. This will automatically hide the new row. As a result, the GridNewRowBehavior will be never used because you don't have a new row at all. I would like to note that when you set the AllowAddNewRow property to true and display the new row, pressing the Tab key in the last editable columns will insert the row in the data rows collection automatically. However, if you need to add a new row after editing the Rate column in a data row, it is appropriate to handle the GridDataRowBehavior.
public RadForm1()
{
    InitializeComponent();
 
    radGridView1.AllowAddNewRow = false;
    radGridView1.AddNewRowPosition = SystemRowPosition.Bottom;
    radGridView1.Rows.AddNew();
 
    BaseGridBehavior gridBehavior = radGridView1.GridBehavior as BaseGridBehavior;
    gridBehavior.UnregisterBehavior(typeof(GridViewDataRowInfo));
    gridBehavior.RegisterBehavior(typeof(GridViewDataRowInfo), new MyGridBehavior());
 
    radGridView1.Columns["Column1"].IsCurrent = true;
    radGridView1.BeginEdit();
}
 
public class MyGridBehavior : Telerik.WinControls.UI.GridDataRowBehavior
{
    protected override bool ProcessTabKey(KeyEventArgs keys)
    {
        if (this.GridControl.CurrentCell.ColumnIndex == this.GridControl.Columns.Count - 1 &&
            this.GridControl.CurrentCell.RowIndex == this.GridControl.Rows.Count - 1)
        {
            this.GridControl.Rows.AddNew();
            return true;
        }
 
        return base.ProcessTabKey(keys);
    }
}

I hope this information helps. If you have any additional questions, please let me know. 

Regards,
Dess
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Gopinath
Top achievements
Rank 1
answered on 07 Apr 2017, 12:57 PM

Hi Dess,

Thanks for the reply. It is working fine, but after Column3 it is adding the row but cursor remains in the same column.

It should go to column1 again to continue enter the data in the next row. After adding the row the cursor should select column1.

I tried working with UserAddedRow, and User AddingRow, it is not working.

Now how to set cursor to  the column1. I tried the follwing code. Expecting your earliest reply.

  private void RadGridView1_UserAddingRow(object sender, GridViewRowCancelEventArgs e)
        {
            radGridView1.Columns["Column1"].IsCurrent = true;
            radGridView1.BeginEdit();
        }

        private void RadGridView1_UserAddedRow(object sender, GridViewRowEventArgs e)
        {
            radGridView1.Columns["Column1"].IsCurrent = true;
            radGridView1.BeginEdit();
        }

Regards

Gopinath

 

0
Gopinath
Top achievements
Rank 1
answered on 07 Apr 2017, 01:24 PM

Hi Dess

Pl find enclosed image for your information.

Regards

Gopinath

 

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 07 Apr 2017, 01:28 PM
Hello Gopinath, 

Thank you for writing back. 

The UserAdding and UserAdded events are fired when the user commits the new row (by pressing the Enter key or by clicking somewhere in the grid). When you add the row programmatically, these events are not supposed to be fired. However, in order to focus the first column after a new record is inserted, you can set the RadGridView.CurrentColumn. Here is a sample code snippet:

public class MyGridBehavior : Telerik.WinControls.UI.GridDataRowBehavior
{
    protected override bool ProcessTabKey(KeyEventArgs keys)
    {
        if (this.GridControl.CurrentCell.ColumnIndex == this.GridControl.Columns.Count - 1 &&
            this.GridControl.CurrentCell.RowIndex == this.GridControl.Rows.Count - 1)
        {
            this.GridControl.Rows.AddNew();
            this.GridControl.CurrentColumn = this.GridControl.Columns[0];
            return true;
        }
 
        return base.ProcessTabKey(keys);
    }
}

I hope this information helps. If you have any additional questions, please let me know. 

Regards,
Dess
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Gopinath
Top achievements
Rank 1
answered on 08 Apr 2017, 01:58 AM

Hi Des,

Thanks for the reply. I was trying to work with IsCurrent method in the class, so it was not working. I hope it works, I will try.

How can i move rows up and down in the grid, by pressing UP Arrow and DownArrow Key. Is there any way to do this?

Expecting your reply.

Regards

Gopinath

0
Hristo
Telerik team
answered on 10 Apr 2017, 02:08 PM
Hi Gopinath,

Thank you for writing.

I hope that the approach suggested by my colleague would fit your actual project.

I would like to point out that we also strive to keep our forum threads more or less focused on a single topic. Regarding your other question please open a support ticket or a new forum thread.

I hope this helps. Please let me know if you have other questions.

Regards,
Hristo
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Gopinath
Top achievements
Rank 1
answered on 11 Apr 2017, 07:21 AM

Hi

Thank you for replying.  The above solution working good. thanks for that.

I have raised another forum thread.

Regards

Gopinath

 

 

Tags
GridView
Asked by
Paidakal
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Gopinath
Top achievements
Rank 1
Hristo
Telerik team
Share this question
or