Forum Discussion

kandy1984's avatar
kandy1984
Contributor
7 years ago

Cant click an item in the grid by the name

Hi,

 

I need to be able to click an item on the gridcontrol by name. At the moment, the object spy is highlighting only the grid and not the items in the grid to select. The items can be specified by wValue(Row, Coulmn) where the row will be fixed. I need to be able to find the item by name, for example, "Truck 01" and click on it as it can be anywhere on the list. Pls see attached images for the grid view and the Properties.

 

Thanks for helping,

Sudha

 

 

5 Replies

  • shankar_r's avatar
    shankar_r
    Community Hero

    Hi,

     

    For clicking an cell you can use yourGridObject.ClickCell(row,col)

     

     

    Scenario #1:

    If your "Truck 01" value can be anywhere in the grid in the sense it can be in col_1, row_1 or col_2, row_4 or col_6, row_3

     

    You need to loop thru each and every cell and find out which cell has that value,

    Scenario #2:

    If your "Truck 01" value will be in the 2nd column of the table then you only need to loop thru rows not column and also there is a function called FindRow(col,colvalue) but not that will used in your AUT object.

     

    Solutions:

    function test()
    {
          //if you don't know which column it has this value 
          toClickTableCell("Truck 01");
          //if you know which column it has this value
          toClickTableCell1("Truck 01",2);    
    } 
    function toClickTableCell(valuetoFind)
    {
          for(var i = 0 ; i < yourGridObject.wRowCount ; i++)
          {
                for(var j = 0 ; j < yourGridObject.wColumnCount ; j++) 
                {
                      if(yourGridObject.wValue(i,j) == valuetoFind)
                      {
                            yourGridObject.ClickCell(i,j);
                            return true
                      }
                }
          }
          return false;
    }
    function toClickTableCell1(valuetoFind,col)
    {
          for(var i = 0 ; i < yourGridObject.wRowCount ; i++)
          {
                if(yourGridObject.wValue(i,col) == valuetoFind)
                {
                      yourGridObject.ClickCell(i,j);
                      return true
                }
          }
          return false;
    }