How to get informations about selected lines in a grid control?

Hi,

Could someone tell me what are services, interfaces, methods used to get informations about a selected of lines from a grid control ?
Any javascript (or basic) Code are welcome.

Thanks


A table control with a push button (“Take focus on click”=False") calling this code:

Sub mri_FormController(ev)
srv = createUnoService("mytools.Mri")
srv.inspect( getFormController(ev.Source))
End Sub

getFormController is a handy function to get the form controller from any form or form control.
The MRI window shows the 1-based selection indices in hex notation for the current control’s selection.
You find getFormController and related code in https://ask.libreoffice.org/uploads/short-url/1yAlwoKjpgsuYkMrf25xCiFGReG.odt

I don’t know if this is helpful to you, but I’m using this procedure to update two columns in a control table. It uses the UNO interface ‘com.sun.star.form.XForm’.

'*********************************************************************
' Procedure name: UpdateDaysOnFormOpen
'
' Description:
' This procedure is triggered when the 'frm-Viewings' form is loaded.
' It updates the "NbJours" column in the form's table control
' by calculating the difference between the current date and the availability date ("DateAvailable").
' If the number of remaining days is less than or equal to zero, a message informs the user
' that the episode is available. After the notification, the values ​​of the "NbJours" and "DateAvailable" columns are cleared.
'
' Input parameter:
' - oEvent: Reference to the event triggered by the form loading.
'
' Special conditions:
' - The "NbJours" and "DateAvailable" columns must exist in the table control.
'**********************************************************************

Sub UpdateDaysOnFormOpen(oEvent As Object)
    Dim dCurrentDate As Date, dAvailableDate As Date
    Dim iColAvailableDate As Integer, iColDaysLeft As Integer, iColEpisode As Integer, iColEnglishTitle As Integer
    Dim iNumberOfDays As Integer, iNewValue As Integer
    Dim oForm As Object
    Dim sAvailableDate As String, sEpisode As String, sEnglishTitle As String

    oForm = oEvent.Source

    ' Assure que le formulaire est chargé correctement
    If hasUnoInterfaces(oForm, "com.sun.star.form.XForm") Then
        iColDaysLeft = oForm.findColumn("NbJours")					' Colonne NbJours
        iColAvailableDate = oForm.findColumn("DateDisponible")		' Colonne DateDisponible
        iColEpisode = oForm.findColumn("NoEpisode")					' Colonne Episode
        iColEnglishTitle = oForm.findColumn("TitreAnglais1")		' Colonne TitreAnglais1
        dCurrentDate = DateValue(Now())								' Récupère la date courante (sans le temps)

        oForm.first()	' Parcourez tous les enregistrements du formulaire
        
        Do While Not oForm.isAfterLast()
            sAvailableDate = oForm.getString(iColAvailableDate)		' Obtenez la date de disponibilité saisie

            If sAvailableDate <> "" Then								' Si 'DateDisponible' n'est pas vide
                dAvailableDate = CDate(sAvailableDate)
               
                ' NbJours entre la date actuelle et la date disponible
                iNumberOfDays = DateDiff("d", dCurrentDate, dAvailableDate)
                iNewValue = iNumberOfDays	' Met à jour 'NbJours' si la différence est différente de la valeur actuelle
                
                If oForm.getInt(iColDaysLeft) <> iNewValue Then
                    oForm.updateInt(iColDaysLeft, iNewValue)
                    oForm.updateRow()								' Sauvegarde l'enregistrement après la mise à jour
                End If
                    
                ' Affiche le message lorsque le nombre de jours restants est inférieur ou égal à zéro
                If iNewValue <= 0 Then
                    ' Récupérer les valeurs des colonnes 'Episode' et 'TitreAnglais1'
                    sEpisode = oForm.FormatString(iColEpisode)
                    sEnglishTitle = oForm.getString(iColEnglishTitle)
                    Beep
                        
                    ' Message à l'utilisateur
                    MsgBox "Episode " & sEpisode & " (" & sEnglishTitle & ") est maintenant disponible."

                    ' Effacer les valeurs de 'NbJours' et 'DateDisponible'
                    oForm.updateNull(iColDaysLeft)             ' Efface la valeur de 'NbJours'
                    oForm.updateNull(iColAvailableDate)        ' Efface la valeur de 'DateDisponible'
                    oForm.updateRow()                          ' Sauvegarde l'enregistrement après la mise à jour
                End If
            End If

            oForm.next()	'Passe à l'enregistrement suivant
        Loop
    End If
	oForm.reload()			' Rafraichissement du formulaire.   
End Sub

Thank for your code. It works fine for me to the getSelection() line. But how to get data with XResultSet and XRow from oSelection ?

Store the position numbers in an array. Walk through the position numbers. The FormController’s FormOperations allow this. My sample code includes a routine Sub MoveToRecord_5(ev). For each record, read data from the form itself. A form is also a record set supporing methods like getString, getInt, getDate etc.