﻿<?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 - Updating the grid using Enter and Down Arrow Keys</title><link>http://www.intersoftsolutions.com/Community/WebGrid/Updating-the-grid-using-Enter-and-Down-Arrow-Keys/</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>Updating the grid using Enter and Down Arrow Keys</title><link>http://www.intersoftsolutions.com/Community/WebGrid/Updating-the-grid-using-Enter-and-Down-Arrow-Keys/</link><pubDate>Thu, 01 Nov 2012 06:31:53 GMT</pubDate><dc:creator>Hans</dc:creator><description>&lt;p&gt;Hello,&lt;br&gt;&lt;/br&gt; &lt;br&gt;&lt;/br&gt;Thank you for your information.&lt;/p&gt;
&lt;p&gt;If you wish to have a row to see the total from one of Webgrid’s column, you could use AggregateFunction property.&lt;/p&gt;
&lt;p&gt;I bind Webgrid to Products table and I set ColumnFooters property to Yes.&lt;br&gt;&lt;/br&gt;In UnitsInStock column, I set AggregateFunction property to Sum.&lt;/p&gt;
&lt;p&gt;The total value will be updated if I update the value in UnitsInStock column.&lt;/p&gt;
&lt;p&gt;Please have review on my sample to the result.&lt;/p&gt;
&lt;p&gt;However, if this solution doesn’t meet the requirement of your scenario, could you please provide a simple runnable project? So I can help you to find the solution.&lt;/p&gt;
&lt;p&gt;Thank you. &lt;/p&gt;
&lt;p&gt;Regards,&lt;br&gt;&lt;/br&gt;Hans.&lt;/p&gt;</description></item><item><title>Updating the grid using Enter and Down Arrow Keys</title><link>http://www.intersoftsolutions.com/Community/WebGrid/Updating-the-grid-using-Enter-and-Down-Arrow-Keys/</link><pubDate>Wed, 31 Oct 2012 18:12:56 GMT</pubDate><dc:creator>adajani@najiasystems.com</dc:creator><description>Great, this seems to work. Now I have a new issue with the actual update event.&lt;br /&gt;&lt;br /&gt;I am not doing any batch updates. So if I move off the row, the grid updates the data. Currently, when I get the data to bind to data source, I do some totaling in the background. So Let's say the first 5 rows are details and the 6th row is the total line. If I update a value in row 3, column 2, then I should see the total reflected immediately in row 6 column 2. However, this isn't happening. When I move off the row I am updating, the grid does indeed and update and the value gets written to the database, but the total doesn't come up. It seems the grid only updates the row I changed. As a workaround, I added the following call in my ObjectDataSource OnUpdating event:&lt;br /&gt;&lt;br /&gt;WebGrid1.ClientAction.Refresh()&lt;br /&gt;&lt;br /&gt;This works great. Unfortunately, when this code is implemented, if I hit down/up arrow or enter key as we've been discussing above, the focus is no longer on the cell in IE. The focus become on the body element. So clicking right/left arrows moves my whole page and not the grid. &lt;br /&gt;&lt;br /&gt;So I'm stuck, again...&lt;br /&gt;&lt;br /&gt;My setup is grid bound to object data source, plus all the code above. My ObjectDataSource on Updating call either has ClientSide.Refresh() call which puts the focus on the wrong element in IE only, or I take it out and my grid doesn't show the right totals.&lt;br /&gt;&lt;br /&gt;Anything we can do here in this event or in the activateEditMode call? Basically, If I update a cell, I need to update the whole column or the whole grid.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;/**        * Some manual behavior for navigating the grid
        */
        function wb_OnEditKeyDown(controlId, keyCode) {
            var returnVal = true;
            // get the grid
            var grid = ISGetObject(controlId);
            // get current information about row and cell
            var activeEditCell = grid.GetActiveEditCell();
            var curRow = activeEditCell.rowElement;
            var curRowIndex = curRow.rowIndex;
            var curCell = grid.GetActiveEditCell().cellIndex;
            var curRowEl = grid.RootTable.GetRow(curRowIndex);
            var cell = curRowEl.GetCell(curCell - 1);
            if (keyCode == 38) { // if up arrow
                grid.ExitEdit(1, 0, 0);  // exit and update the row if dirty
                activateEditMode(grid, curRowIndex, curRowIndex - 1, curCell - 1);
            }
            else if (keyCode == 40 || keyCode == 13) {  // if down arrow or enter key
                keyCode = 40;
                event.keyCode = 40;
                //returnVal = true;
                event.returnValue = false;
                grid.ExitEdit(1, 0, 0);  // exit and update the row if dirty
                activateEditMode(grid, curRowIndex, curRowIndex &amp;#43; 1, curCell - 1);
            }
            else if (keyCode == 27) {   // esc key
                cell.Select(true);
            }
            return returnVal;
        }&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;Thanks!&lt;br /&gt;
</description></item><item><title>Updating the grid using Enter and Down Arrow Keys</title><link>http://www.intersoftsolutions.com/Community/WebGrid/Updating-the-grid-using-Enter-and-Down-Arrow-Keys/</link><pubDate>Tue, 30 Oct 2012 07:42:00 GMT</pubDate><dc:creator>Hans</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Thank you for your reply.&lt;/p&gt;
&lt;p&gt;After I change the doctype, I can replicate your issue on my end as well.&lt;/p&gt;
&lt;p&gt;To resolve this issue please try to modify the code in keyDown javascript function.&lt;br&gt;&lt;/br&gt;From:&lt;/p&gt;&lt;pre&gt;nextRowEl.Select();&lt;/pre&gt;
&lt;p&gt;To:&lt;/p&gt;&lt;pre&gt;nextRowEl.Select(true);&lt;/pre&gt;
&lt;p&gt;This workaround works on my end.&lt;/p&gt;
&lt;p&gt;Regards,&lt;br&gt;&lt;/br&gt;Hans.&lt;/p&gt;</description></item><item><title>Updating the grid using Enter and Down Arrow Keys</title><link>http://www.intersoftsolutions.com/Community/WebGrid/Updating-the-grid-using-Enter-and-Down-Arrow-Keys/</link><pubDate>Mon, 29 Oct 2012 12:43:38 GMT</pubDate><dc:creator>adajani@najiasystems.com</dc:creator><description>Hans, &lt;br /&gt;&lt;br /&gt;Thanks for the answer, but I am still having issues...I can't believe this really..&lt;br /&gt;&lt;br /&gt;If you change your code's doctype to: &amp;lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&amp;gt; you will notice issues with the behavior. Switching to HTML 4.0 doctype is not an option for me. It must be the other.&lt;br /&gt;&amp;nbsp;&lt;br /&gt;Specifically the problem I am having now is in IE. If I edit a cell and move off it either by arrows or enter key, the cursor does not select the appropriate cell. If I hit the down arrow key, I should go to the below cell and so forth. Right now, the focus is lost. If you hit the side arrows you will notice the first cell in the next row is selected.&lt;br /&gt;</description></item><item><title>Updating the grid using Enter and Down Arrow Keys</title><link>http://www.intersoftsolutions.com/Community/WebGrid/Updating-the-grid-using-Enter-and-Down-Arrow-Keys/</link><pubDate>Sun, 28 Oct 2012 22:13:21 GMT</pubDate><dc:creator>Hans</dc:creator><description>&lt;p&gt;Hello,&lt;br&gt;&lt;/br&gt; &lt;br&gt;&lt;/br&gt;I’m sorry for the late response.&lt;/p&gt;
&lt;p&gt;Please try to too add this code below in WebGrid1_OnEditKeyDown client side event:&lt;/p&gt;&lt;pre&gt;var curRowEl = grid.RootTable.GetRow(curRow);
var cell = curRowEl.GetCell(curCell - 1);
if (event.keyCode == 27) {
    cell.Select(true);
}&lt;/pre&gt;
&lt;p&gt;Hope this helps.&lt;/p&gt;
&lt;p&gt;Regards,&lt;br&gt;&lt;/br&gt;Hans.&lt;/p&gt;</description></item><item><title>Updating the grid using Enter and Down Arrow Keys</title><link>http://www.intersoftsolutions.com/Community/WebGrid/Updating-the-grid-using-Enter-and-Down-Arrow-Keys/</link><pubDate>Fri, 26 Oct 2012 14:46:56 GMT</pubDate><dc:creator>adajani@najiasystems.com</dc:creator><description>Hello?</description></item><item><title>Updating the grid using Enter and Down Arrow Keys</title><link>http://www.intersoftsolutions.com/Community/WebGrid/Updating-the-grid-using-Enter-and-Down-Arrow-Keys/</link><pubDate>Thu, 25 Oct 2012 11:40:35 GMT</pubDate><dc:creator>adajani@najiasystems.com</dc:creator><description>&lt;p&gt;This works. I found out the issue with focus. I was causing a differnet Refresh on the OnUpdating event. &lt;br /&gt;&lt;/p&gt;
&lt;p&gt;But this isn't the full solution. I marked the answer too soon. &lt;br /&gt;&lt;/p&gt;
&lt;p&gt;Now in Firefox, the edit makes it through and I'm set in the edit mode for the cell directly under. That's good. However, if I hit 'esc' key, it takes me to the first cell in that row. Why does that happen and how can I stop that from happening?&lt;/p&gt;
&lt;p&gt;In IE 9, it goes directly to the first cell in the next row.&lt;br /&gt;&lt;/p&gt;

</description></item><item><title>Updating the grid using Enter and Down Arrow Keys</title><link>http://www.intersoftsolutions.com/Community/WebGrid/Updating-the-grid-using-Enter-and-Down-Arrow-Keys/</link><pubDate>Thu, 25 Oct 2012 03:00:59 GMT</pubDate><dc:creator>Hans</dc:creator><description>&lt;p&gt;Hello,&lt;br&gt;&lt;/br&gt; &lt;br&gt;&lt;/br&gt;Thank you for your patience.&lt;/p&gt;
&lt;p&gt;I have modified your wbAARS_OnEditKeyDown function and activateEditMode function.&lt;/p&gt;
&lt;p&gt;Please let me know the result on your end.&lt;/p&gt;
&lt;p&gt;Regards,&lt;br&gt;&lt;/br&gt;Hans.&lt;/p&gt;</description></item><item><title>Updating the grid using Enter and Down Arrow Keys</title><link>http://www.intersoftsolutions.com/Community/WebGrid/Updating-the-grid-using-Enter-and-Down-Arrow-Keys/</link><pubDate>Wed, 24 Oct 2012 10:16:58 GMT</pubDate><dc:creator>adajani@najiasystems.com</dc:creator><description>&lt;p&gt;This works fine, but I still have the problem of losing focus on the cell. The focus goes back on the browser window and not the cell. So then if I click left or right, I am no longer navigating in the grid.&lt;/p&gt;
&lt;p&gt;If you can't recreate the issue, can you tell me why in IE the body element takes focus instead of it going back to the grid? &lt;/p&gt;
&lt;p&gt;I am trying to get on the Live Chat for techinical assistance and it won't let me due to some user name and password. Can you please provide so I may solve this problem?&lt;br /&gt;&lt;/p&gt;
</description></item><item><title>Updating the grid using Enter and Down Arrow Keys</title><link>http://www.intersoftsolutions.com/Community/WebGrid/Updating-the-grid-using-Enter-and-Down-Arrow-Keys/</link><pubDate>Wed, 24 Oct 2012 06:11:36 GMT</pubDate><dc:creator>Hans</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Thank you for your reply.&lt;/p&gt;
&lt;p&gt;After I investigate this issue further more.&lt;br&gt;&lt;/br&gt;I remove a couple line of code.&lt;/p&gt;
&lt;p&gt;In WebGrid1_InitializePostBack, I remove:&lt;/p&gt;&lt;pre&gt;If (e.Action.Equals("Refresh"))&lt;/pre&gt;
&lt;p&gt;And in SaveScrollPosition function, I remove:&lt;/p&gt;&lt;pre&gt;if (action == "Refresh")&lt;/pre&gt;
&lt;p&gt;Please have a review on my sample and let me know the result.&lt;/p&gt;
&lt;p&gt;Thank you.&lt;/p&gt;
&lt;p&gt;Regards,&lt;br&gt;&lt;/br&gt;Hans.&lt;br&gt;&lt;/br&gt;&lt;/p&gt;</description></item><item><title>Updating the grid using Enter and Down Arrow Keys</title><link>http://www.intersoftsolutions.com/Community/WebGrid/Updating-the-grid-using-Enter-and-Down-Arrow-Keys/</link><pubDate>Sat, 20 Oct 2012 15:26:06 GMT</pubDate><dc:creator>adajani@najiasystems.com</dc:creator><description>&lt;p&gt;I'd like to be able to cause the grid to update after I edit a cell by hitting the enter or down arrow key. &lt;br /&gt;Hitting either of those keys should update the grid, move down one cell and place it in Edit Mode ready for editing. Much like Excel.&lt;/p&gt;
&lt;p&gt;What happens now is if I hit the down arrow key, the grid updates but does not move focus to the below cell. The enter key behaves differently in IE and Firefox. In IE, the grid updates just fine. However, in Firefox, the whole page refreshes and the change is not applied.&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;The update works if I tab off or move or move to the left/right cell.&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;My code is below. I'm binding the grid to an Object Data Source. &lt;br /&gt;&lt;/p&gt;&lt;pre&gt;&amp;lt;ISWebGrid:WebGrid ID="WebGrid1" runat="server" Width="100%" Height="100%" UseDefaultStyle="true" EnableWebResources="Always"
                           DataSourceID="odsAccountLineList" CustomSchemaRetrieval="UseWebGrid"&amp;gt;
            &amp;lt;RootTable GridLineStyle="NotSet" DataKeyField="account_line_id" RowHeaders="Yes"&amp;gt;
            &amp;lt;/RootTable&amp;gt;
            &amp;lt;LayoutSettings DisplayDetailsOnUnhandledError="true"           
                            InProgressUIBehavior="ChangeCursorToHourGlass" StatusBarVisible="true"
                            NewRowLostFocusAction="AlwaysUpdate"
			    RowLostFocusAction="AlwaysUpdate" 
                            AllowColumnMove="Yes"
			    AllowFilter="No" 
                            AllowGrouping="No" 
                            AllowSelectColumns="Yes" 
                            AllowSorting="No"
			    GroupByBoxVisible="false" 
                            AutoHeight="false" 
                            AutoWidth="false" 
                            PagingMode="None"
                            AllowEdit="Yes" 
                            AllowDelete="Yes"
                            AllowMultipleSelection="Yes"
                            UseRelativePositioning="true"
                            CellClickAction="CellSelect"
                            ApplyChangesKey="Enter"&amp;gt;
                &amp;lt;AlternatingRowStyle CustomRules="text-overflow: ellipsis; overflow-x: hidden" BackColor="LightGray" Wrap="false" Font-Size="8pt" Font-Names="Arial Monospaced"&amp;gt;&amp;lt;/AlternatingRowStyle&amp;gt;
                &amp;lt;RowStyle CustomRules="text-overflow: ellipsis; overflow-x: hidden" BackColor="White" Font-Size="8pt" Wrap="false" Font-Names="Arial Monospaced"&amp;gt;&amp;lt;/RowStyle&amp;gt;
                &amp;lt;ClientSideEvents OnRowContextMenu="wb_OnRowContextMenu" OnColumnContextMenu="wb_OnColumnContextMenu"
                    OnEnterEditMode="wb_OnEnterEditMode" OnScroll="wb_OnScroll" OnEditKeyDown="wb_OnEditKeyDown" /&amp;gt;
		    &amp;lt;/LayoutSettings&amp;gt;
        &amp;lt;/ISWebGrid:WebGrid&amp;gt;&lt;/pre&gt;
&lt;p&gt;Client Side JS. I am not including all the client side events. Nothing out of the ordinary is happening there and they are working just fine:&lt;/p&gt;&lt;pre&gt;/**
        * Activates Edit Mode for the specified row and column
        */
        function activateEditMode(grid, rowIndex, columnName) {
            if (rowIndex != 0 &amp;amp;&amp;amp; rowIndex &amp;lt; grid.TotalRows) {
                var myRow = grid.RootTable.GetRow(rowIndex);
                myRow.BeginEdit();
                myRow.GetCell(columnName).ActivateEdit();
            }
        }&lt;/pre&gt;&lt;pre&gt;/**
        * Some manual behavior for navigating the grid
        */
        function wbAARS_OnEditKeyDown(controlId, keyCode) {
            // get the grid
            var grid = ISGetObject(controlId);
            // get current information about row and cell
            var activeEditCell = grid.GetActiveEditCell();
            var columnName = wgGetColNameByCell(activeEditCell.element);
            var curRow = activeEditCell.rowElement;
            var curRowIndex = curRow.rowIndex;
            if (keyCode == 38) { // if up arrow
                grid.ExitEdit(1, 0, 0);  // exit and update the row if dirty
                activateEditMode(grid, curRowIndex - 1, columnName);
            }&lt;br /&gt;// Note(XX): I was testing for the enter key here to apply the same logic as the down arrow key&lt;br /&gt;&amp;nbsp;//            else if (keyCode == 13 || keyCode == 40) {  // if down arrow or enter key
            else if (keyCode == 40) {  // if down arrow or enter key
                grid.ExitEdit(1, 0, 0);  // exit and update the row if dirty
                activateEditMode(grid, curRowIndex &amp;#43; 1, columnName);
            } 
            return true;
        }&lt;/pre&gt;
&lt;p&gt;As I understand it, when I call ExitEdit, it refreshes the grid and waits for an XML response back. So activateEditMode gets called, but when the response is received, the focus is returned back to the original editted cell.&lt;/p&gt;
&lt;p&gt;Your help is appreciataed. Thanks.&lt;br /&gt;&lt;/p&gt;</description></item></channel></rss>