Completed
Last Updated: 07 Mar 2016 14:38 by ADMIN
ADMIN
Dess | Tech Support Engineer, Principal
Created on: 09 Feb 2016 11:59
Category: GridView
Type: Bug Report
1
FIX. RadGridView - incorrect grid navigation when pressing Tab key in the new row placed at the bottom of the grid and the last visible column is read-only
To reproduce:

public Form1()
{
    InitializeComponent();
    DataTable dt = new DataTable();
    for (int i = 0; i < 10; i++)
    {
        dt.Columns.Add("Col" + i);
    }

    for (int i = 0; i < 10; i++)
    {
        DataRow row = dt.NewRow();
        foreach (DataColumn col in dt.Columns)
        {
            row[col.ColumnName] = "Data " + i + "." + dt.Columns.IndexOf(col);
        }
        dt.Rows.Add(row);
    }
    this.radGridView1.DataSource = dt;
    this.radGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;

    this.radGridView1.AddNewRowPosition = Telerik.WinControls.UI.SystemRowPosition.Bottom;
    this.radGridView1.Columns[9].IsVisible = false;
    this.radGridView1.Columns[8].ReadOnly = true;

    this.radGridView1.Columns[2].IsVisible = false;
    this.radGridView1.Columns[4].IsVisible = false;
    this.radGridView1.Columns[6].IsVisible = false;
}


Workaround: use a custom row behavior and control what to be the selected cell when pressing the Tab key for example: 

public Form1()
{
    InitializeComponent();
    DataTable dt = new DataTable();
    for (int i = 0; i < 10; i++)
    {
        dt.Columns.Add("Col" + i);
    }

    for (int i = 0; i < 10; i++)
    {
        DataRow row = dt.NewRow();
        foreach (DataColumn col in dt.Columns)
        {
            row[col.ColumnName] = "Data " + i + "." + dt.Columns.IndexOf(col);
        }
        dt.Rows.Add(row);
    }
    this.radGridView1.DataSource = dt;
    this.radGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;

    this.radGridView1.AddNewRowPosition = Telerik.WinControls.UI.SystemRowPosition.Bottom;
    this.radGridView1.Columns[9].IsVisible = false;
    this.radGridView1.Columns[8].ReadOnly = true;

    this.radGridView1.Columns[2].IsVisible = false;
    this.radGridView1.Columns[4].IsVisible = false;
    this.radGridView1.Columns[6].IsVisible = false;

    //register the custom row  behavior
    BaseGridBehavior gridBehavior = radGridView1.GridBehavior as BaseGridBehavior;
    gridBehavior.UnregisterBehavior(typeof(GridViewNewRowInfo));
    gridBehavior.RegisterBehavior(typeof(GridViewNewRowInfo), new CustomGridHierarchyRowBehavior());
}

public class CustomGridHierarchyRowBehavior : GridNewRowBehavior
{
    protected override bool ProcessTabKey(KeyEventArgs keys)
    {
        bool isLastColumn = this.Navigator.IsLastColumn(this.GridControl.CurrentColumn);
        bool result = base.ProcessTabKey(keys);
        if (isLastColumn)
        {
            this.GridControl.CurrentColumn = this.GridControl.Columns[0];
            this.GridControl.BeginEdit();
        }
        return result;
    }
}
Attached Files:
0 comments