-1

I have a GridView in SAP GUI and want to check if a line is already selected or not.

The following code checks if the grid contains data. But I struggle with the check if a specific row is selected:

Set objGRID1 = SAPSession.findById("wnd[0]/usr/cntlGRID1/shellcont/shell/shellcont[1]/shell")

If objGRID1.RowCount = 0 Then
    MsgBox "Keine Daten vorhanden!!" & Chr(10) & "Makro wird beendet!", vbCritical
    End
End If

For dblZeile = 0 To objGRID1.RowCount - 1

????

Next dblZeile

Can anybody could help me on this?

Best regards, Lutz

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
  • 1
    You can look at all possibilities in the documentation of the [GuiGridView Object](https://help.sap.com/docs/search?q=GuiGridView%20Object&product=sap_gui_for_windows&version=latest). – Sandra Rossi Jan 10 '23 at 12:13
  • Hi Sandra, unfortunately I don't get my problem solved with the link. How do I have to set up the code that at the end a certain number of rows are selected? – Lutz Fricke Jan 10 '23 at 15:10
  • What did you try? What issue do you have? Please provide detailed information. – Sandra Rossi Jan 10 '23 at 15:17
  • I don't understand what's in your link. I've tried the other answer (which is now gone...) with the following code: Set objGRID1 = SAPSession.findById("wnd[0]/usr/cntlGRID1/shellcont/shell/shellcont[1]/shell") selectedRows = objGRID1.GetSelectedRows() and got an run-time error 438 "Object doesn't support this property or method" in the last line. Even if I Dim'd "selectedRows" as variant or array. – Lutz Fricke Jan 10 '23 at 15:33
  • 1
    `GetSelectedRows` is not a valid method of GuiGridView Object as you can see in the documentation I mentioned. Hopefully, you can find everything possible. What don't you understand in the documentation? Maybe it's a good question to ask. This way, you'll be able to find by yourself. – Sandra Rossi Jan 10 '23 at 16:23
  • 1
    I think `SelectedRows` is the right property to use in this case. _The string is a comma separated list of row index numbers or index ranges, such as “1,2,4-8,10”_ Anyway, [_Can anybody could help me on this?_](https://meta.stackoverflow.com/questions/284236/why-is-can-someone-help-me-not-an-actual-question) is not a question one can answer. – Storax Jan 10 '23 at 19:21

1 Answers1

-1

my starting problem was to select a number of rows out of a existing selection of rows in a SAP GUI GridView (e.g. the first 5 lines out of 1,2,4-8,10). I've planned to check each row if it's selected and count the selcted rows until the number of rows is reached. After that I planned to deselect the following rows.

Finally I solved the problem with the following code:

Set objGRID1 = SAPSession.findById("wnd[0]/usr/cntlGRID1/shellcont/shell/shellcont[1]/shell")
    
If objGRID1.RowCount = 0 Then
    MsgBox "Keine Daten vorhanden!!" & Chr(10) & "Makro wird beendet!", vbCritical
    End
End If

strStartRows = objGRID1.selectedRows
strStartRows = strStartRows & ",,"

strBins = ""
intCounter = 0

Do
    strCheck = Left(strStartRows, InStr(1, strStartRows, ",", 1) - 1)

    If InStr(1, strCheck, "-", 1) > 0 Then
        For intDurchlauf = CInt(Left(strCheck, InStr(1, strCheck, "-", 1) - 1)) To CInt(Right(strCheck, Len(strCheck) - InStr(1, strCheck, "-", 1)))
            strBins = strBins & intDurchlauf & ","
            intCounter = intCounter + 1
            If intCounter >= intMaxBins Then
                Exit Do
            End If
        Next intDurchlauf
    Else
        strBins = strBins & strCheck & ","
        intCounter = intCounter + 1
        If intCounter >= intMaxBins Then
            Exit Do
        End If
    End If

    strStartRows = Right(strStartRows, Len(strStartRows) - InStr(1, strStartRows, ",", 1))
Loop Until strStartRows = ","

objGRID1.selectedRows = Left(strBins, Len(strBins) - 1)

It works fine, but probably it's not the best code for this. Please feel free to correct, if there's something to do better.

Thanks for your help, Lutz