﻿<?xml version="1.0" encoding="utf-8"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:media="http://search.yahoo.com/mrss/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><title>Intersoft Community - WebGrid Enterprise - How to activate edit mode</title><link>http://www.intersoftsolutions.com/Community/WebGrid/How-to-activate-edit-mode/</link><description /><generator>http://www.intersoftsolutions.com</generator><language>en</language><copyright>Copyright 2002 - 2015 Intersoft Solutions Corp. All rights reserved.</copyright><ttl>60</ttl><item><title>How to activate edit mode</title><link>http://www.intersoftsolutions.com/Community/WebGrid/How-to-activate-edit-mode/</link><pubDate>Thu, 24 Oct 2013 03:45:40 GMT</pubDate><dc:creator>yudi</dc:creator><category>WebGrid</category><description>&lt;p&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;I test the JS function on a hierarchical WebGrid and find that when user press ‘left’ or ‘right’ key from keyboard, the JS function does activate edit on the incorrect cell. Based on my test result, the term “&lt;em&gt;incorrect cell&lt;/em&gt;” is the cell on the right-side of the correct one.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;If you are dealing with the same problem, please modify following line in the WebGrid1_OnKeyDown JS function.&lt;/span&gt;&lt;/p&gt;&lt;pre&gt;function WebGrid1_OnKeyDown(controlId, tblName, rowIndex, cellIndex)
{
    var WebGrid1 = ISGetObject(controlId);
    if (event.keyCode &amp;gt; 36 &amp;amp;&amp;amp; event.keyCode &amp;lt; 41)
    {
        var selectedRow = WebGrid1.GetSelectedObject().GetRowObject();
                
        // check if selected row's type is Record
        if (selectedRow.Type == "Record")
        {
            if (event.keyCode == 40)
            {
                ...
            }
            // if 'up' key is pressed
            else if (event.keyCode == 38)
            {
                ...
            }
                    
            // the original is:
            // else
            //     var selectedCell = selectedRow.GetCells()[GetCurrentActiveCellIndex(WebGrid1) - 1];
            else
                var selectedCell = selectedRow.GetCells()[GetCurrentActiveCellIndex(WebGrid1) - 2];
            ...
        }
    }
    return true;
}&lt;/pre&gt;
&lt;p&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;The reason why we need to modify that line is that WebGrid with hierarchical structure has different layout compared to the non-hierarchical one. It has one column added on left side which is used to place the expand/collapse child-table button.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;Hope this helps.&lt;/span&gt;&lt;/p&gt;</description></item><item><title>How to activate edit mode</title><link>http://www.intersoftsolutions.com/Community/WebGrid/How-to-activate-edit-mode/</link><pubDate>Mon, 21 Oct 2013 17:32:25 GMT</pubDate><dc:creator>luwen</dc:creator><category>WebGrid</category><description>&lt;p&gt;Thanks Yudi. This works when grid does not have child table.  How to calculate the ColumnIdx when the grid uses child table? &lt;/p&gt;</description></item><item><title>How to activate edit mode</title><link>http://www.intersoftsolutions.com/Community/WebGrid/How-to-activate-edit-mode/</link><pubDate>Wed, 16 Oct 2013 04:53:49 GMT</pubDate><dc:creator>yudi</dc:creator><category>WebGrid</category><description>&lt;p&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;I haven’t had a chance to tidy up the following code.&lt;/span&gt;&lt;/p&gt;&lt;pre&gt;function WebGrid1_OnKeyDown(controlId, tblName, rowIndex, cellIndex){
    var WebGrid1 = ISGetObject(controlId);
            
    // check if user press the arrow keys
    if (event.keyCode &amp;gt; 36 &amp;amp;&amp;amp; event.keyCode &amp;lt; 41)
    {
        var selectedRow = WebGrid1.GetSelectedObject().GetRowObject();
        // check if selected row's type is Record
        if (selectedRow.Type == "Record")
        {
            if (event.keyCode == 40)
            {
                if (selectedRow.Position != WebGrid1.TotalRows - 1)
                    var rowIndex = selectedRow.Position &amp;#43; 1;
                else
                    var rowIndex = selectedRow.Position;
                        
                var selectedCell = WebGrid1.RootTable.GetRow(rowIndex).GetCells()[GetCurrentActiveCellIndex(WebGrid1) - 1];
            }
            else if (event.keyCode == 38)
            {
                if (selectedRow.Position != 0)
                    var rowIndex = selectedRow.Position - 1;
                else
                    var rowIndex = selectedRow.Position;
                var selectedCell = WebGrid1.RootTable.GetRow(rowIndex).GetCells()[GetCurrentActiveCellIndex(WebGrid1) - 1];
            }
            else
                var selectedCell = selectedRow.GetCells()[GetCurrentActiveCellIndex(WebGrid1) - 1];
            // check if selected cell is editable or not
            if (selectedCell.IsEditable())
            {
                window.setTimeout(function () { selectedCell.ActivateEdit(); }, 100);
            }
        }
    }
    return true;
}
function GetCurrentActiveCellIndex(gridObj)
{
    var grid = ISGetObject(gridObj);
    var activeCell = grid.GetActiveEditCell();
    var curCellIndex = activeCell.cellIndex;
    if (event.keyCode == 37 || event.keyCode == 39)
    {
        if (event.keyCode == 37 &amp;amp;&amp;amp; curCellIndex != null)
            curCellIndex = curCellIndex - 1;
        if (event.keyCode == 39 &amp;amp;&amp;amp; curCellIndex != 6)
            curCellIndex = curCellIndex &amp;#43; 1;
    }
    return curCellIndex;
}&lt;/pre&gt;
&lt;p&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;Please attach the WebGrid1_OnKeyDown JS function to WebGrid’s OnKeyDown client-side event. The JS code will manually activate edit mode on each selected cell when user navigates using the arrow key on keyboard.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;Please let us know whether this helps or not.&lt;/span&gt;&lt;/p&gt;</description></item><item><title>How to activate edit mode</title><link>http://www.intersoftsolutions.com/Community/WebGrid/How-to-activate-edit-mode/</link><pubDate>Mon, 14 Oct 2013 18:05:19 GMT</pubDate><dc:creator>luwen</dc:creator><category>WebGrid</category><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I use a dropdown list inside a webgrid. Our applicaiton allows user to use 4 arrow keys to move the cursor.  The code works fine except when the cursor comes to a dropdown list column. Your first key stoke is always ignored ( it is used to force the dropdown list into edit mode). How to avoid that?  &lt;/p&gt;
&lt;p&gt;I attach the screen shot and code. Here is the way to reproduce the problem. Click column "Tav Tax Code"; Press right arrow key,  you see the cursor jumps to "Revised Tran Type" Column; press a number, for example 2, the dropdown list turns into edit mode, but the select is not changed;  Press 2 again, the selection changed. &lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;Luwen&lt;/p&gt;</description></item></channel></rss>