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

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
teneighty
Posts: 7
Joined: Sun Nov 22, 2015 6:11 am

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

Post by teneighty »

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

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
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

Post by MTP »

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

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
RPG
Volunteer
Posts: 2250
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

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

Post by RPG »

Hello

Maybe this thread can help you.

Romke
LibreOffice 7.1.4.2 on openSUSE Leap 15.2
teneighty
Posts: 7
Joined: Sun Nov 22, 2015 6:11 am

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

Post by teneighty »

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
Post Reply