-1

I m using excel VBA to try and automate some SAP data entry.

I have a gridview control that I m trying to find specific text in a column, then double-clicked that cell to select it.

I m currently using a for loop to find the row but getting some strange result. When I step through the code, I can get to the row but cannot select or double-click it. When the code runs at the usual speed, the row is not even selected!

Is there a better way to go about this?

This is the code is have so far

 Function SelectRowOnGrid(grid As SAPFEWSELib.GuiGridView, columnname As String, texttofind As String) 

        For i = 0 To grid.RowCount - 1

            If grid.GetCellValue(i, columnname) = texttofind Then
                grid.DoubleClickCurrentCell
            End If

        Next i

End Function

I have also tried the following code:

    Function SelectRowOnGrid(grid As SAPFEWSELib.GuiGridView, columnname As String, texttofind As String)

        For i = 0 To grid.RowCount - 1

          If InStr(1, grid.GetCellValue(i, columnname), texttofind, 1) > 0 Then

            If selectedRows = "" Then
              selectedRows = CStr(i)
                Else
              selectedRows = selectedRows + "," + CStr(i)
            End If

          End If

        Next i

    grid.selectedRows = selectedRows

End Function

Any help is appreciated !

cheers

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Nick
  • 3,454
  • 6
  • 33
  • 56

1 Answers1

4

You have to select the cell before double clicking:

If grid.GetCellValue(i, columnname) = texttofind Then
    grid.SetCurrentCell(i, columnname)
    grid.DoubleClickCurrentCell
End If