http://www.intersoftpt.com/Community/WebGrid/the-grid-using-Left-and-Right-Arrow-Keys/

5 replies. Last post: July 20, 2014 10:18 PM by Hans Kristian
Tags :
  • New Discussion
  • New Question
  • New Product Feedback
Sun BennyMember

Hi ,

I want to use left or right key in webgrid, But I just found the keys to move up and down the line of code, I do not know how to move around key column is implemented, could help me write an example, thank you.

The following are the up and down keys code:

function WebGrid1_OnEditKeyDown(controlId) {
            var grid = ISGetObject("WebGrid1");

            var totalRows = grid.TotalRows;
            var curRow = grid.GetSelectedObject().rowIndex;
            var curCell = grid.GetActiveEditCell().cellIndex;

            var curRowEl = grid.RootTable.GetRow(curRow);
            var cell = curRowEl.GetCell(curCell - 1);

            // if ESC key
            if (event.keyCode == 27) {
                cell.Select(true);
            }

            // if ENTER key
            if (event.keyCode == 13) {
                event.keyCode = 40;
            }

            // if UP arrow key
            if (event.keyCode == 38) {
                if (curRow > 0) {
                    keyDownRow(curRow, curRow - 1, curCell - 1);
                }
            }

            //if left arrow key
            if (event.keyCode == 37) {
                //
            }

            //if right arrow key
            if (event.keyCode == 39) {

            }

            // if DOWN arrow key
            else if (event.keyCode == 40) {
                if (curRow < totalRows - 1) {
                    keyDownRow(curRow, curRow + 1, curCell - 1);
                }
            }

            return true;

        }

function keyDownRow(curRow, nextRow, cell) {
            var grid = ISGetObject("WebGrid1");
            var nextRowEl = grid.RootTable.GetRow(nextRow);
            var curRowEl = grid.RootTable.GetRow(curRow);
            var cell1 = nextRowEl.GetCell(cell);
            var cell2 = curRowEl.GetCell(cell);
            grid.SetFocus();
            cell2.Select(true);
            nextRowEl.Select(true);
            cell1.ActivateEdit();
        }

 

All times are GMT -5. The time now is 8:54 AM.
Previous Next