Creating a new row on tab-out of an Infragistics UltraWebGrid

I had a need to do this today, and it took me longer than it should have to research and paste together the fragments I found around the net. I don’t have a whole lot of experience with the Ultra Web Grid and maybe this is something that is obvious for those that do.

Below is the exact code that should work to create a new row when the user presses tab at the end of the last existing row in an Infragistics UltraWebGrid.

First, inside your grid’s

element, add the following declaration:


Then add this JavaScript either in the page or in an external script file:

        // Add a new row to the UltraWebGrid if we tab out of the last row
        function uwgKeyDown(gridName, itemName, keyStroke) {
            // This should only fire when you leave a row, not when you are in a row.

            // Make sure we are tabbing out before we do anything else
            if (keyStroke == 9)
                // Get the grid object
                var gridControl = igtbl_getGridById(gridName);

                // Get the cell object
                var cell = igtbl_getCellById(gridControl.ActiveCell);

                // Where are we?
                var lastRowIndex = gridControl.Rows.length - 1;
                var lastColumnIndex = gridControl.Bands[0].Columns.length - 1

                // See if the ActiveCell is in the last column
                if (cell.Column.Index == lastColumnIndex)
                    // See if we are in the last row
                    if (cell.Row.getIndex() == lastRowIndex)
                        // Add a row after the last row
                        igtbl_addNew(gridName, lastRowIndex);

This should work for any grid you use. Let me know if there are any issues with this or instances where it doesn’t work!

Posted Friday, March 18th, 2011 under .NET.

Leave a Reply