add a new row to RadGridView

2 posts, 1 answers
  1. Manjit
    Manjit avatar
    3 posts
    Member since:
    May 2012

    Posted 01 Aug 2012 Link to this post

    Hi, I want to add a new row to a RadGridView via automation. I've searched the forums but haven't found this topic yet.
    I see that there is a NewRow property, in my case..
    Pages.USSPOSCOIndustries.FrameHome.SilverlightApp.GridviewEarnings.NewRow

    There is also a function called AddNewRow which I assume is used to make the new row.
    So I'm guessing I have to set each column in my NewRow then call AddNewRow to commit it. But I don't know how to loop through each column in my row to set each columns value.
    So far I have...

    Telerik.WebAii.Controls.Xaml.RadGridView rgv = Pages.USSPOSCOIndustries.FrameHome.SilverlightApp.GridviewEarnings;
    int rowCounter = rgv.Rows.Count;
    int cellCounter = 1; 
     
    foreach(Telerik.WebAii.Controls.Xaml.GridViewCell gCell in Pages.USSPOSCOIndustries.FrameHome.SilverlightApp.GridviewEarnings.NewRow) { //Nested loop; Goes through all the cells within each row
               
         if (gCell.XamlTag == "textbox" && gCell.AutomationId == "PART_EditableTextBox")
            gCell.Text = (string)(System.Convert.ChangeType(Data["Hours"], typeof(string)));
            //You can implement any type of verification you like against the text here
     
         if (gCell.XamlTag == "selectivescrollinggrid" && gCell.Name == "grid")
            gCell.Text = (string)(System.Convert.ChangeType(Data["Hours"], typeof(string)));
            //You can implement any type of verification you like against the text here
     
            cellCounter++;
        }
        rowCounter++;

         Pages.USSPOSCOIndustries.FrameHome.SilverlightApp.GridviewEarnings.AddNewRow();

    Is this correct? Also, I would like to search by xamlpath as well as xamlTag for a column's textbox, dropdown, etc. Is this possible?

    Thanks for the help
  2. Answer
    Cody
    Admin
    Cody avatar
    3354 posts

    Posted 06 Aug 2012 Link to this post

    Hello,

    To go along with my response to your support ticket on the same question, here's code I got working on this sample page:

    RadGridView grid = ActiveBrowser.SilverlightApps()[0].Find.ByAutomationId<RadGridView>("RadGridView1");
     
    grid.Rows[0].Cells[0].User.Click();
    Manager.Desktop.KeyBoard.KeyPress(System.Windows.Forms.Keys.Insert);
     
    Manager.Desktop.KeyBoard.TypeText("79");
    Manager.Desktop.KeyBoard.KeyPress(System.Windows.Forms.Keys.Tab);
    Manager.Desktop.KeyBoard.TypeText("New Product Name");
    Manager.Desktop.KeyBoard.KeyPress(System.Windows.Forms.Keys.Tab);
    Manager.Desktop.KeyBoard.TypeText("14.35");
    Manager.Desktop.KeyBoard.KeyPress(System.Windows.Forms.Keys.Tab);
    Manager.Desktop.KeyBoard.TypeText("42");
    Manager.Desktop.KeyBoard.KeyPress(System.Windows.Forms.Keys.Enter);
    Kind regards,
    Cody
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
Back to Top