[Solved] How to read values from selected rows in a table

Creating a macro - Writing a Script - Using the API

[Solved] How to read values from selected rows in a table

Postby teneighty » Mon Feb 01, 2016 4:44 am

How can the values be read from a particular column in a table in a form? The idea is to be able to select multiple rows, and then trigger a macro with a button that will read the ID on only the selected rows, in order to know which records to update.

So far, I can get the ID value on the current row. And I can also get the selected rows. But I can't figure out how to get any other value out of the ID column besides the current value. My thought is that either I can use the row number to get the values from the selected rows, or I have to set the current row and then get the current value for each selected row.

This is what I have so far:
Code: Select all   Expand viewCollapse view
Sub UpdateRequests(oEvent as object)
   Dim oForm, oSelection, oTable, oTableControl, oSelectedRows as object
   oForm = oEvent.Source.Model.Parent
   oTable = oForm.getByName("Table1")
   oTableControl = ThisComponent.getCurrentController().getControl(oTable)
   oSelectedRows = oTableControl.getSelection()
   oGridView = oForm.Parent.Parent.CurrentController.getControl(oTable)
   
oTablemodel=oForm.getbyname("Table1") ' Get now the table control you need
a=oTableModel.getbyname("NumericField1") ' Get now the control inside the tablecontrol

'print a.boundfield.getstring ' print now the fieldvalue
'print a.currentvalue

   oGridView.select(3)
   oMRI.inspect(oGridView)
End Sub


oGridView.select() is based on another post, but I can't get it to work. I was hoping it would allow me to change the current row so I could get use currentvalue to get values from different columns.
Last edited by teneighty on Tue Feb 02, 2016 5:21 am, edited 1 time in total.
OpenOffice 4.1.2 on Kubuntu 14.04.3
teneighty
 
Posts: 7
Joined: Sun Nov 22, 2015 6:11 am

Re: Base: how to read values from selected rows in a table

Postby MTP » Mon Feb 01, 2016 5:07 pm

You have to set the current row, and then can get the values from the selected row. It may be easiest to just work at the form level with something like
Code: Select all   Expand viewCollapse view
oForm.absolute(oSelectedRows(n))
i = oForm.columns.ColumnName.getInt()
s = oForm.columns.ColumnName2.getString()

That avoids having to work with the table control too much.
OpenOffice 4.1.1 on Windows 10, HSQLDB 1.8 split database
User avatar
MTP
Volunteer
 
Posts: 1620
Joined: Mon Sep 10, 2012 7:31 pm
Location: Midwest USA

Re: Base: how to read values from selected rows in a table

Postby RPG » Mon Feb 01, 2016 7:25 pm

Hello

Maybe this thread can help you.

Romke
LibreOffice 6.3.3.2 on openSUSE Leap 15
RPG
Volunteer
 
Posts: 2193
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

[SOLVED] Base: how to read values from selected rows in a ta

Postby teneighty » Tue Feb 02, 2016 5:20 am

RPG wrote:Hello

Maybe this thread can help you.

Romke


Yes, that's pretty much exactly what I'm trying to do! Thanks

And thanks MTP, that's also some interesting code I will examine as well, the more I can learn the better.
OpenOffice 4.1.2 on Kubuntu 14.04.3
teneighty
 
Posts: 7
Joined: Sun Nov 22, 2015 6:11 am


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 7 guests