OnKeyPress Event

10 posts, 0 answers
  1. Ganga
    Ganga avatar
    37 posts
    Member since:
    Nov 2010

    Posted 18 Aug 2011 Link to this post

     

    Hi,

    I have an scenario to set cell value on a data grid by using with OnKeypress event. It is working and I can able to set value to the first selected row cell, but I couldn’t able to set the value to next selected row cell. It is always trying to set the value to first selected row cell instead of set value to next selected row cell.


    I have noticed the first row cell is still selected even though I have select the next row cell. My issue, I don’t know how to clear onkeypress event from first row cell after set value.


    Please help me in resolving this problem. I am looking for a C# code example.


    Waiting for your reply.

    Thanks

    Ganga S

  2. Cody
    Admin
    Cody avatar
    3354 posts

    Posted 19 Aug 2011 Link to this post

    Hi Ganga,

    Could you share with us the code you are using to invoke the OnKeypress event? I am going to guess it resembles this:

    Pages.AdDetails.CarDetailsBodyCodeSelect.InvokeEvent(ScriptEventType.OnKeyPress);


    The above code is tied to a specific element. It will invoke the OnKeyPress event for that specific element only, without regard for which row or element currently has input focus. You must get a wrapper object that represents the input element contained on second row so you can invoke the OnKeyPress event on it. How this is done depends on the exact structure of your data grid. If you can share your code and the HTML (I assume this is an HTML application, not a Silverlight application) code for your entire data grid I can assist with putting together the code to interact with it properly.

    Best wishes,
    Cody
    the Telerik team
    Vote for Telerik Test Studio at the Annual Automation Honors Voting!
  3. Ganga
    Ganga avatar
    37 posts
    Member since:
    Nov 2010

    Posted 21 Aug 2011 Link to this post

    Hi Cody,

    Appreciate your quick response.

    I have attached HTML Code for data grid and frame work code for on key press.  Addition to this I have attached screen shot of the data grid.

    Thanks
    Ganga S

  4. Cody
    Admin
    Cody avatar
    3354 posts

    Posted 22 Aug 2011 Link to this post

    Hi Ganga,

    I see by the HTML code that your data isn't presenting in an actual <table> element. Instead it's formatted to look like a table using <div> and <span> elements with CSS formatting.

    I looked at your code, but can't really make sense out of it. It's just 3 subroutines, not the main test. I see where you're calling OnKeyPress:

    // 12-Aug-2011 Invoke the DOM Change event
    //Added the OnFocus and OnKeyPress events to resolve the issue with XE datagrid AJAX issue.
    // Without this code, I can’t set the value to the cell
    element.OwnerBrowser.Actions.InvokeEvent(element, ScriptEventType.OnKeyPress);

    However I don't see the definition for "element" nor do I see where it gets initialized to a value. Thus I have no idea what "element" represents.

    However based on your HTML alone, if I were implementing the test, I would use a subroutine like this:

    public void InvokeKeyPress(string col, int row)
    {
        HtmlSpan spanTable = ActiveBrowser.Find.ById<HtmlSpan>("ctlPageControl_grdDealTypes_RowsHolder");
        HtmlSpan rowSpan = spanTable.ChildNodes[row].As<HtmlSpan>();
        HtmlSpan cellSpan;
        switch (col)
        {
            case "Sequence":
                cellSpan = rowSpan.ChildNodes[0].As<HtmlSpan>();
                break;
     
            case "Module":
                cellSpan = rowSpan.ChildNodes[0].As <HtmlSpan>();
                break;
     
            case "Instrument":
                cellSpan = rowSpan.ChildNodes[0].As <HtmlSpan>();
                break;
     
            case "Deal Type":
                cellSpan = rowSpan.ChildNodes[0].As <HtmlSpan>();
                break;
     
            default:
                throw new Exception("Column name " + col + " is not recognized.");
        }
        cellSpan.InvokeEvent(ScriptEventType.OnKeyPress);
    }


    Kind regards,
    Cody
    the Telerik team
    Vote for Telerik Test Studio at the Annual Automation Honors Voting!
  5. Ganga
    Ganga avatar
    37 posts
    Member since:
    Nov 2010

    Posted 23 Aug 2011 Link to this post

    Hi Cody,

     

    Once again, really appreciate your help.

     

    This is not standard html controls. In our framework we have base provider, which is contains all methods for standard control, if a application uses different type of control we simply inherit the base and override methods.

     

    Please refer the attached screen shot

     

    Based on your code, how do I cancel the on Key press event after set the value to a cell?

     

     

    Thanks

    Ganga S

  6. Cody
    Admin
    Cody avatar
    3354 posts

    Posted 23 Aug 2011 Link to this post

    Hi Ganga,

    I am sorry but I am confused by your request "how do I cancel the on Key press event after set the value to a cell?" The reason for my confusion is that OnKeyPress is an event (i.e. a message), it is not "cancelable". You send the event to your web application as a way of notifying the application that a key was pressed. You either send it or you don't send it. It's not like a mode you can turn on/off.

    Can you please clarify what you mean by "cancel the on Key press event"? What action in the UI or web application are you looking to accomplish, or what problem are you trying to solve?

    Regards,
    Cody
    the Telerik team
    Vote for Telerik Test Studio at the Annual Automation Honors Voting!
  7. Ganga
    Ganga avatar
    37 posts
    Member since:
    Nov 2010

    Posted 23 Aug 2011 Link to this post

    Hi Cody,

    This will give some more information about my requirement. I am really appreciate your help.

    What is happening in Web UI: (refer attached "datagrid.png" screen shot)

    Via my code (Automation):
    1) Select a cell
    2) Onkeypress to invoke the cell
    3) Set the value
    4) Then select the next cell

    Actual: the focus is still in the previous cell (please refer to attached screen). Due to that I can’t set value to next cell.

    Expected: the focus should be changed to next cell (same as manual action).

    How do I change focus to next cell (similar to manual action), so I can able to set the value to next cell?

    Manual Action:
    5) Double click to select a cell
    6) Set the value
    7) Then select next cell (the focus is changed to next cell, please refer the screen shot)

    Thanks
    Ganga S


  8. Cody
    Admin
    Cody avatar
    3354 posts

    Posted 24 Aug 2011 Link to this post

    Hello Ganga,

    Thank you for the clarification. I can think of a couple of possible approaches. Try these and see which one works for you:

    public void test()
    {
        EnterData("Module", 0, "mod1");
        EnterData("Instrument", 0, "mod1");
        EnterData("Deal Type", 0, "mod1");
     
        EnterData("Module", 1, "mod1");
        EnterData("Instrument", 1, "mod1");
        EnterData("Deal Type", 1, "mod1");
    }
     
    public void EnterData(string col, int row, string value)
    {
        HtmlSpan spanTable = ActiveBrowser.Find.ById<HtmlSpan>("ctlPageControl_grdDealTypes_RowsHolder");
        HtmlSpan rowSpan = spanTable.ChildNodes[row].As<HtmlSpan>();
        HtmlSpan cellSpan;
        switch (col)
        {
            case "Sequence":
                cellSpan = rowSpan.ChildNodes[0].As<HtmlSpan>();
                break;
     
            case "Module":
                cellSpan = rowSpan.ChildNodes[0].As<HtmlSpan>();
                break;
     
            case "Instrument":
                cellSpan = rowSpan.ChildNodes[0].As<HtmlSpan>();
                break;
     
            case "Deal Type":
                cellSpan = rowSpan.ChildNodes[0].As<HtmlSpan>();
                break;
     
            default:
                throw new Exception("Column name " + col + " is not recognized.");
        }
        cellSpan.InvokeEvent(ScriptEventType.OnKeyPress);
        Manager.Desktop.KeyBoard.TypeText(value, 10, 10);
        Manager.Desktop.KeyBoard.KeyPress(System.Windows.Forms.Keys.Tab);
    }

    Using Mouse.Click instead of OnKeyPress:
    public void test()
    {
        EnterData("Module", 0, "mod1");
        EnterData("Instrument", 0, "mod1");
        EnterData("Deal Type", 0, "mod1");
     
        EnterData("Module", 1, "mod1");
        EnterData("Instrument", 1, "mod1");
        EnterData("Deal Type", 1, "mod1");
    }
     
    public void EnterData(string col, int row, string value)
    {
        HtmlSpan spanTable = ActiveBrowser.Find.ById<HtmlSpan>("ctlPageControl_grdDealTypes_RowsHolder");
        HtmlSpan rowSpan = spanTable.ChildNodes[row].As<HtmlSpan>();
        HtmlSpan cellSpan;
        switch (col)
        {
            case "Sequence":
                cellSpan = rowSpan.ChildNodes[0].As<HtmlSpan>();
                break;
     
            case "Module":
                cellSpan = rowSpan.ChildNodes[0].As<HtmlSpan>();
                break;
     
            case "Instrument":
                cellSpan = rowSpan.ChildNodes[0].As<HtmlSpan>();
                break;
     
            case "Deal Type":
                cellSpan = rowSpan.ChildNodes[0].As<HtmlSpan>();
                break;
     
            default:
                throw new Exception("Column name " + col + " is not recognized.");
        }
        Manager.Desktop.Mouse.Click(MouseClickType.LeftDoubleClick, cellSpan.GetRectangle());
        Manager.Desktop.KeyBoard.TypeText(value, 10, 10);
        Manager.Desktop.KeyBoard.KeyPress(System.Windows.Forms.Keys.Tab);
    }

    Greetings,
    Cody
    the Telerik team
    Vote for Telerik Test Studio at the Annual Automation Honors Voting!
  9. Ganga
    Ganga avatar
    37 posts
    Member since:
    Nov 2010

    Posted 13 Sep 2011 Link to this post

    Hi Cody,

     

    First off couple of weeks, I apologize for the delay responding back to you.

     

    I tried with your code, but it is not working. Having said that, based on your idea, it tried few testing to figure out to solve the problem. I have resolved the issue by doing this;

     

    I have use  OnkeyPress event to make that cell editable

    Set the value into the cell

    then OnMouseDown event to make that cell not editable mode. By doing this: the edited cell was changed to not editable and I was able to set the value to next row cell.

     

    Thanks a lot your valuable support.

     


    Regards

    Ganga S

  10. Cody
    Admin
    Cody avatar
    3354 posts

    Posted 14 Sep 2011 Link to this post

    Hi Ganga,

    That's good news. I am glad you found a workable solution. Thanks for the update.

    Best wishes,
    Cody
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top