OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

The value of a column in the selected row of a table control

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Base
View previous topic :: View next topic  
Author Message
leeand00
General User
General User


Joined: 01 Jul 2007
Posts: 24

PostPosted: Wed Jul 18, 2007 7:29 am    Post subject: The value of a column in the selected row of a table control Reply with quote

How can I obtain the value of a column in the selected row of a table control?

Thank you,
Andrew J. Leer
Back to top
View user's profile Send private message
Decker87
OOo Enthusiast
OOo Enthusiast


Joined: 21 May 2007
Posts: 163

PostPosted: Wed Jul 18, 2007 7:41 am    Post subject: Reply with quote

From where? Macros?
If so, the easiest way is to create a RowSet object, navigate to the row, and use the GetInt method.

Code:
Dim SQL_Code as string, oRS as object

   oRS = createUnoService("com.sun.star.sdb.RowSet")
   oRS.ActiveConnection = oFormEditVehicles.ActiveConnection
   
   SQL_Code="SELECT column2 FROM table WHERE column2=5"

   oRS.Command = SQL_Code
   oRS.execute

   IF oRS.next THEN
      ValueOfFirstColumn=oRS.getInt(1)
   END IF


*Navigate to the right row with oRS.next or some other method, then use GetInt(#) or GetString(#) to return the value of the #th column in that row.
*Set the active connection to the active connection of your form, in most cases
*You have to use the execute method to actually use the command you specified.

Don't thank me, thank Mark B!




EDIT: I just realized you said table control, and not table! I will try to find that answer for you too!
Back to top
View user's profile Send private message
leeand00
General User
General User


Joined: 01 Jul 2007
Posts: 24

PostPosted: Wed Jul 18, 2007 8:08 am    Post subject: Reply with quote

Thank you for being so diligent Decker! Very Happy
Back to top
View user's profile Send private message
Decker87
OOo Enthusiast
OOo Enthusiast


Joined: 21 May 2007
Posts: 163

PostPosted: Wed Jul 18, 2007 8:30 am    Post subject: Reply with quote

You can get the number of the row with this property of the control:
.Model.Parent.Row
This will give you the number of the row that is selected. However, I believe that OOoB does not store any information about which column AND row are selected. If you absolutely need to discern which column has focus, I don't know how.

Code:

Dim oTable 'This is the table control
Dim RowNum

RowNum=oTable.Model.Parent.Row


Remember that when you use the GetByName or GetByIndex methods, they return the model.
Back to top
View user's profile Send private message
leeand00
General User
General User


Joined: 01 Jul 2007
Posts: 24

PostPosted: Wed Jul 18, 2007 8:52 am    Post subject: Reply with quote

Deker, it's not so much which column has the focus; rather it's what is the primary key of the row that is selected.

Thanks again,
leeand00
Back to top
View user's profile Send private message
Decker87
OOo Enthusiast
OOo Enthusiast


Joined: 21 May 2007
Posts: 163

PostPosted: Wed Jul 18, 2007 10:37 am    Post subject: Reply with quote

Tables have primary keys. Records do not have primary keys.
If you know the order of the columns in the table, then I already explained how to do what you are asking.
Back to top
View user's profile Send private message
leeand00
General User
General User


Joined: 01 Jul 2007
Posts: 24

PostPosted: Wed Jul 18, 2007 10:44 am    Post subject: Reply with quote

Okay my apologies I found it in another thread...

Code:
theForm.getColumns().getByName("col_name").getType


Where getType is getInt, or getString
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Base All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group