Forum Discussion

Amna_Saeed321's avatar
Amna_Saeed321
Occasional Contributor
4 years ago
Solved

How to get the Cell Object which I Clicked using function ClickCell in grid view

I am facing an issue that I cannot access all rows in the Grid view because the row index property "WPFControlOrdinalNo" is returning random numbers if grid is having rows more than 5 rows with vertical scrollbar. 

I can click the cells of specified column through the built in function like this GridObject["ClickCell"](i,DataColRef);

i want to get the cell object i just clicked through function so that i can access the row through parent property and manipulate it as per my test.

 

Would be a great help if someone can assist me.

 

  • Below function will Return i which will give you the cell no and will click on the cell as well with the below parameters:
    Grid - Grid Object
    Column - Column name to be clicked
    Value - Which value to be clicked in Column

    function ClickGrid(Grid,Column,Value)
    {
    var RowIndex;
    function FindRow(Grid, Column, Value, ViewId)
    {
    if (typeof(ViewId) == "undefined")
    ViewId = 0;
    for (var i=0; i<Grid.wRowCount(ViewId); i++)
    if (Grid.wValue(i, Column, ViewId) == Value)
    return i;
    return -1;
    }
    RowIndex = FindRow(Grid,Column,Value);
    if (RowIndex != -1)
    {
    Grid.ClickCell(RowIndex, Column);
    Log.Message("Row index: " + RowIndex + " Column Name: " + Value);
    }
    else
    Log.Error("Row was not found");
    }

4 Replies

  • Marsha_R's avatar
    Marsha_R
    Champion Level 3

    What sort of random?  If it's 20 rows, are you still getting rows numbered 1-20 or 0-19 and they just aren't in the expected order?  Or are you getting strange row index values that have nothing to do with the number of rows?

     

    If you have 0-19 or similar, you could still loop through the rows to process your test.  It would be jumping around on the rows but they would all eventually get processed.

     

    Other options would be

    1) See if there's another index value hidden down in the properties somewhere.

    2) Use something other than the index value to loop through.  If it's always known data, then you could save a table with the text values or whatever you are using and just use that to match each row and loop.

     

    • Amna_Saeed321's avatar
      Amna_Saeed321
      Occasional Contributor

      Like if grid have 10 rows with the scrollbar. property gives index 1 to 5 till row 5 but when i scroll to see rest of the rows it start giving the index of other rows as random number (e.g. 4, 2,1,8) everytime i scroll and access the row with object spy it gives me different number. so i can not access the row with the descriptive programming.

       

      I want to access the cell which is currently clicked in the grid. in that way probably i can get access to all rows.

  • anupamchampati's avatar
    anupamchampati
    Frequent Contributor

    Below function will Return i which will give you the cell no and will click on the cell as well with the below parameters:
    Grid - Grid Object
    Column - Column name to be clicked
    Value - Which value to be clicked in Column

    function ClickGrid(Grid,Column,Value)
    {
    var RowIndex;
    function FindRow(Grid, Column, Value, ViewId)
    {
    if (typeof(ViewId) == "undefined")
    ViewId = 0;
    for (var i=0; i<Grid.wRowCount(ViewId); i++)
    if (Grid.wValue(i, Column, ViewId) == Value)
    return i;
    return -1;
    }
    RowIndex = FindRow(Grid,Column,Value);
    if (RowIndex != -1)
    {
    Grid.ClickCell(RowIndex, Column);
    Log.Message("Row index: " + RowIndex + " Column Name: " + Value);
    }
    else
    Log.Error("Row was not found");
    }