Forum Discussion

shrey1686's avatar
shrey1686
Occasional Contributor
11 years ago

How to get X,Y coordinates of a cell inside a table at run time. ? Given Row & Col Number

 

Hi Team,

 

I want to retrive X and Y coordinates of a cell inside a table(Grid) at run time.  I have the row and column number.

 

I need to simulate a right click on that cell using ClickR property for which I need X & Y parameter.

 

I have been able to access that cell's other properties like Text or Name or Click inside the cell by using following code.

 

Aliases.XXX.MainForm.SplitterPanel2.gridTrades.Rows.Item(0).Cells.Item(14).get_Text

OR

Aliases.XXX.MainForm.SplitterPanel2.gridTrades.Rows.Item(0).Cells.Item(14).Click

 

Here 0 & 14 are Row and Col Number respectively.

 

Please help me out to get the X & Y coordinates of this cell so I can have a Right Click on that cell.

 

Thanks,

Shreyansh Baid

2 Replies

  • shrey1686's avatar
    shrey1686
    Occasional Contributor

    Any one having idea about above question . Getting X,Y coordinates of a Cell at run time..

    In QTP you can use "GetCellProperty" method.  See Below QTP code:

    xCoordinate =    XXX.SwfTable("gridTrades").GetCellProperty (1,1,"x") 

     

    But In test Complete how to do ??

  • You need to calculate the Cells x,y coordinates using the properties like this,this code is for getting cell coordinates of a flex grid in a desktop application. If your application is a web application then you have similar properties ScreenTop,Top,ScreenLeft,Left etc use them and follow exactly the same below logic.

    function GetCellCoordinates(var x:integer,var y:integer;grid:OleVariant,RowIndex:integer,ColIndex:integer,parentObj:OleVariant=nil);
    var
      page,obj:OleVariant;
      cellX,cellY,cellPixRatio : integer;
    begin
      try
        if IsNullNil(parentObj) then
          parentObj := grid.Parent;
        grid.SetFocus;
        grid.Row := RowIndex;
        grid.Col := ColIndex;
        cellX := grid.CellTop + parentObj.Top;
        cellY := grid.CellLeft + parentObj.Left;        
        
        //Convert the CellX and CellY into Pixels
        cellPixRatio := VarToInt(parentObj.ScaleWidth/parentObj.Width);    
        
        x := VarToInt(cellX/cellPixRatio);
        y := VarToInt(cellY/cellPixRatio);
      
        Log.Message('Cell : ' + VarToStr(RowIndex) + ',' + VarToStr(ColIndex) +' Cell Width : ' + VarToStr(grid.CellWidth) + ' X Coord : ' + VarToStr(x) + ' Y Coord : ' + VarToStr(y));          
      except
        Log.Error('Exception in GetCellCoordinates ',exceptionmessage);
      end 
    end;