Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
245
TAB from last cell to first cell
posted

My users wish to be able to edit valuse in an UltraGrid and navigate using the the TAB key.  When they reach the last cell in the last row, the TAB key should take them back to the first cell.

My problem when I implement the solution below, I jump from the last cell to the second cell in the first row.

As  a demo, I create a simple DataTable, add 5 columns and 3 rows:  

 private DataTable m_Data;

 

 

private void Form1_Load(object sender, EventArgs e)

{

m_Data =

new DataTable();

m_Data.Columns.Add(

new DataColumn("column 1", typeof(String)));

m_Data.Columns.Add(

new DataColumn("column 2", typeof(String)));

m_Data.Columns.Add(

new DataColumn("column 3", typeof(String)));

m_Data.Columns.Add(

new DataColumn("column 4", typeof(String)));

m_Data.Columns.Add(

new DataColumn("column 5", typeof(String)));

 

 

DataRow row1 = m_Data.NewRow();

m_Data.Rows.Add(row1);

 

 

DataRow row2 = m_Data.NewRow();

m_Data.Rows.Add(row2);

 

 

DataRow row3 = m_Data.NewRow();

m_Data.Rows.Add(row3);

 

 

this.ultraGrid1.DataSource = m_Data.DefaultView;

}

Now I add this code to check if I am in the last cell, and if so, I want to jump to the first cell:

 

private void ultraGrid1_KeyDown(object sender, KeyEventArgs e)

{

 

 

if (e.KeyCode == Keys.Tab)

{

 

 

int lastRow = ultraGrid1.Rows.Count - 1;

 

 

int lastColumn = ultraGrid1.DisplayLayout.Bands[0].Columns.Count - 1;

 

 

if (ultraGrid1.ActiveCell.Row.Index == lastRow && ultraGrid1.ActiveCell.Column.Header.VisiblePosition == lastColumn)

{

ultraGrid1.PerformAction(

UltraGridAction.FirstCellInGrid);

} } }

The problem is when I do this column2 in the first rows ends up activated, not column1.  Is there a better way to do this?  The current version I am using is 7.3.20073.1061 with all the latest hotfixes.  Thank you.

  • 245
    Suggested Answer
    posted

    I figured it out.  I need to set e.Handled = true after PerformAction(UltraGridAction.FirstCellInGrid) and the add this event handler:

    private void ultraGrid2_AfterCellActivate(object sender, EventArgs e)

    {

    ultraGrid2.PerformAction(UltraGridAction.EnterEditMode);

    }

    Thanks.