Forum Discussion

aldebaran's avatar
aldebaran
Occasional Contributor
15 years ago

Unable to select gridview-cells

Hi all,



My TC-Project needs to select certain rows/cells of a .Net gridview control. Recording KeywordTests saves clicks within the grid with coordinates. The problem with those coordinates occur if those tests are run on a different OS or a different style setting on same OS, meaning one cannot rely upon the coordinates to select certain grid-cells or controls, e.g. checkboxes in grid.



I´m unable to select rows/cells with the provided gridview-methods of the object explorer.

Say I have a grid with 3 rows and 4 columns. Upon setting the grid to editable, the focus is automatically set to the first cell in the last row, often being a new row in grid.

What do I have to do if I need to select the second cell in the first row? How can I use the CallObjectMethods of a gridview to do the trick? Everything I tried didn´t work.



Alternativly using a script-method has the same not satisfying result,



Sub SelectCellForEntries(ColNum, RowNum, nameOfForm)


 Select case nameOfForm


   case "frmXYZ"


        
Aliases.CEBELClient.frmCEBELMDIMain.MdiClient.frmXYZ.grd1(ColNum,
RowNum).Click()

   case Else


         Log.Error "Argument not in case list"   


end Select


End Sub




Can someone provide an example?





greets



Carsten

5 Replies

  • aldebaran's avatar
    aldebaran
    Occasional Contributor
    Silly me,



    found enough help in integrated help.

    Implemented Scrip Method with select case and can set current cell of any of my gridviews now, some code:



    Sub
    SelectCellForEntries(ColumnIdx, RowIndex, nameOfForm)


     Select case nameOfForm


       case "frmXYZ"


    Set Aliases.CEBELClient.frmCEBELMDIMain.MdiClient.frmXYZ.grd1.CurrentCell = Aliases.CEBEL.frmCEBELMDIMain.MdiClient.frmXYZ.grd1.Item(ColumnIdx, RowIndex)

    ....

    ...



    thanx all



    greets c.
  • aldebaran's avatar
    aldebaran
    Occasional Contributor
    Hi everyone,



    I have supplied a solution to click a certain cell, and found out there is a much better solution at hand:

    http://www.automatedqa.com/support/viewarticle/?aid=8998



    However, I would like to select a specific row in a datagridview and set that as the current row.



    Can anyone help me with that?



    all suggestions welcome



    greetings



    carsten
  • Hi,



    Replace the following line in the ClickDataGridViewCell function :

    Call GridObj.Click(bounds.X + bounds.Width / 2, bounds.Y + bounds.Height / 2)




    with the string below:

    Call GridObj.Click(bounds.Height / 2, bounds.Y + bounds.Height / 2)




    Note that, in this case, the third parameter (colId) of this function should be anything greater than 0 and less than gridObj.Columns.Count.
  • Hi,



    Replace the following line in the ClickDataGridViewCell function :

    Call GridObj.Click(bounds.X + bounds.Width / 2, bounds.Y + bounds.Height / 2)




    with the string below:

    Call GridObj.Click(bounds.Height / 2, bounds.Y + bounds.Height / 2)




    Note that, in this case, the third parameter (colId) of this function should be anything greater than 0 and less than gridObj.Columns.Count.