[Solved] Get Value of Selected Item in Subform

Creating and using forms

[Solved] Get Value of Selected Item in Subform

Postby Paul79 » Tue Oct 27, 2009 3:02 am

From in a macro, how do I get the value of the selected item in a subform? I've tried numerous search terms but could not find any answers. Thanks :)
Last edited by Paul79 on Wed Oct 28, 2009 10:05 am, edited 3 times in total.
OpenOffice 3.1.1 / Windows XP Pro
Paul79
 
Posts: 30
Joined: Fri Oct 02, 2009 5:33 am
Location: Australia

Re: Get Value of Selected Row in Subform

Postby RPG » Tue Oct 27, 2009 3:35 am

Hello

You ask how to get the value of a selected row. In the way I understand your question: it is not possible.
You can get the value of a field in a table or the value from a control. When you want have all fields in that row then you have to ask all the all the field one by one.

http://www.oooforum.org/forum/viewtopic ... boundfield
Here is explained two methods how to do.

For a detailed explanation read the tutorial of Benitez
http://www.geocities.com/rbenitez22/OOo/index.html

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

Re: Get Value of Selected Row in Subform

Postby Paul79 » Tue Oct 27, 2009 5:10 am

Hi, I don't quite see what you mean in those links.

I have a subform with a table of filenames. I want to be able to highlight a filename in the subform, then click a button in the main form to open the file that is selected in the subform table.

I can do it with a list box, but I have no idea how to do it with a subform table.
OpenOffice 3.1.1 / Windows XP Pro
Paul79
 
Posts: 30
Joined: Fri Oct 02, 2009 5:33 am
Location: Australia

Re: Get Value of Selected Item in Subform

Postby Paul79 » Tue Oct 27, 2009 9:26 am

I just noticed my original post was titled 'Get Value of Selected Row...' I've changed Row to Item. I just mean I want to get the value of the currently selected item.
OpenOffice 3.1.1 / Windows XP Pro
Paul79
 
Posts: 30
Joined: Fri Oct 02, 2009 5:33 am
Location: Australia

Re: Get Value of Selected Item in Subform

Postby eremmel » Tue Oct 27, 2009 12:00 pm

The most difficult thing is to find the information you need. It is important to use exact phrases. I think that you want to find the row(s) that are selected in a 'Table Control' that is located in a sub form. The following seach in google might be used: +macro +selected +row +"table control" +OOo +Base. One the first page you might have found Selected Rows in a Table Control.
BTW thanks of asking knowing how to do this was also on my todo list.
Is your question answered: edit your initial post add "[Solved]" to the subject and check V
LO4.2.8 for work with ORB; AOO4.1.4,LO5.2.5/6.0.5 on W7E SP1 64bit
It's Microsoft marketing that tells you computers are qualified for non-technicians
User avatar
eremmel
Volunteer
 
Posts: 1036
Joined: Tue Dec 30, 2008 1:15 am
Location: Barneveld, Netherlands

Re: Get Value of Selected Item in Subform

Postby RPG » Tue Oct 27, 2009 12:54 pm

Hello

It make no difference for accessing a value from a grid or a control: use the current field value of the form where the table control exist.
A table control is a part of a form and the current record follows the form.
There is an important different with other controls. The grid control acts like a container for other controls. You can access this controls byname.

It also give some more capabilities for selecting columns.
It is posible to change the status of visibillitie of a single control or the complete table control

This different ways how it looks as other controls can maybe explain why the event seems to be not working.

edit only little text errors

Romke

This code I have only used for testing

Code: Select all   Expand viewCollapse view
Sub Main
dim oDoc
dim oForm
dim oTablemodel,oTableView
oDoc=thiscomponent.drawpage.forms
oForm=oDoc.getbyname("Standard")
oTablemodel=oForm.getbyname("TableControl")
if not globalscope.BasicLibraries.islibraryloaded("Tools") then
   ' Laad nu de library
   globalscope.BasicLibraries.loadlibrary("Tools")
end if
oTableView = GetControlview(thiscomponent,thiscomponent.getCurrentController,oTablemodel.name)
'oTableView.setVisible(not oTableView.isvisible) 'Complete table control
'print oTableView.isvisible
dim oControl
oControl=oTablemodel.getbyindex(1) ' Single control ' You also use byname I think
oControl.hidden=not oControl.hidden
'print oControl.hidden
end sub



This part is added later and shows how easy it can be to get a field value from a grid control. I think it can also be easy to change the values.
Code: Select all   Expand viewCollapse view
Sub boundfield_test
' Object you must define
dim oDoc
dim oForm
dim oControl
oDoc=thiscomponent.drawpage.forms ' Get document Object and goto the forms
oForm=oDoc.getbyname("Standard") ' Get now the Form you need
oTablemodel=oForm.getbyname("TableControl") ' Get now the table control you need
a=oTablemodel.getbyname("TextField2") ' Get now the control inside the tablecontrol
print a.boundfield.getstring ' print now the fieldvalue
End Sub
Last edited by RPG on Tue Oct 27, 2009 4:42 pm, edited 2 times in total.
LibreOffice 6.1.5.2 on openSUSE Leap 15
RPG
Volunteer
 
Posts: 2164
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

Re: Get Value of Selected Item in Subform

Postby RPG » Tue Oct 27, 2009 1:06 pm

Hello

This link explain it maybe better

http://api.openoffice.org/docs/common/r ... XGrid.html

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

Re: Get Value of Selected Item in Subform

Postby Paul79 » Wed Oct 28, 2009 7:02 am

Thanks for that information. I will try soon.
Paul79
 
Posts: 30
Joined: Fri Oct 02, 2009 5:33 am
Location: Australia

Re: Get Value of Selected Item in Subform

Postby Paul79 » Wed Oct 28, 2009 10:04 am

Here is my working code:

Code: Select all   Expand viewCollapse view
Sub sub_table_test()
  dim oDoc, oForm, oSubForm, oSubFormGrid, f as Object
  oDoc=thiscomponent.drawpage.forms
  oForm=oDoc.getbyname("MainForm")
  oSubForm=oForm.getbyname("sub_pages")
  oSubFormGrid=oSubForm.getbyname("sub_pages_grid")
  f = oSubFormGrid.GetByName("field_filename")
  'Xray f
  MsgBox (f.boundfield.getstring)
End Sub


Thanks all for your help.

EDIT: I should add that this does not get the value of the item you have the cursor on, but just gets one particular field you have specified (in this case 'field_fieldname'). I used this function in a sub table that has a list of filenames (as well as other fields). All I wanted was the filename so I could click a button to view the file.
OpenOffice 3.1.1 / Windows XP Pro
Paul79
 
Posts: 30
Joined: Fri Oct 02, 2009 5:33 am
Location: Australia

Re: [Solved] Get Value of Selected Item in Subform

Postby sdruvss » Mon Dec 30, 2013 1:42 am

How about this code:

Code: Select all   Expand viewCollapse view
Sub myGetSelectedValue

DIM oDoc AS OBJECT
DIM oDrawpage AS OBJECT
DIM oForm AS OBJECT
DIM oTable AS OBJECT
DIM oGrid AS OBJECT
DIM oColumn AS OBJECT
DIM oColumnList AS OBJECT
DIM stContent AS STRING

oDoc = thisComponent
oDrawpage = oDoc.drawpage
oForm = oDrawpage.forms.getByName("MainForm")
oTable = oForm.getByName("SubForm")
oGrid = oTable.getByName("SubForm_Grid")
oColumnList = oGrid.getByName("ColumnField")
stContent = oColumnList.getCurrentValue()
Print stContent

End Sub
LibreOffice 4.1 on Windows 8
sdruvss
 
Posts: 1
Joined: Mon Dec 30, 2013 1:34 am


Return to Forms

Who is online

Users browsing this forum: No registered users and 1 guest