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
50
Override Tab behaviour
posted

We have a solution where we need be able to only tab between editable cells in a grid. The default behavior of the tab is to select the next cell in the grid. Is there any way to override this, so that clicking tab the grid will select the next editable cell in the grid?

Regards

Bjarne

Parents
  • 4940
    Offline posted

    Here's one way to achieve the skipping of cells. It uses the ActiveCellChanged event of the XamGrid. Some further work could be done to improve it.

     

    void theGrid_ActiveCellChanged(object sender, EventArgs e)
    {
        int currindex = 0;
    
        if (YOUR LOGIC HERE COMPARING IF THE CELL SHOULD BE SKIPPED)
        {
            foreach (Infragistics.Controls.Grids.Cell cell in theGrid.ActiveCell.Row.Cells)
            {
                if (cell.IsActive)
                {
                    if ((theGrid.Rows[theGrid.ActiveCell.Row.Index].Cells.Count - 1) > currindex)
                    {
                        theGrid.Rows[theGrid.ActiveCell.Row.Index].Cells[currindex + 1].IsActive = true;
                        theGrid.Rows[theGrid.ActiveCell.Row.Index].Cells[currindex + 1].IsSelected = true;
                        return;
                    }
                    else
                    {
                        if ((theGrid.Rows.Count - 1) >= theGrid.ActiveCell.Row.Index)
                            return;
    
                        theGrid.Rows[theGrid.ActiveCell.Row.Index + 1].Cells[0].IsActive = true;
                        theGrid.Rows[theGrid.ActiveCell.Row.Index].Cells[currindex + 1].IsSelected = true;
                        return;
                    }
                }
    
                currindex++;
            }
        }
    }
    

     

Reply Children