| View previous topic :: View next topic |
| Author |
Message |
leeand00 General User

Joined: 01 Jul 2007 Posts: 24
|
Posted: Wed Jul 18, 2007 7:29 am Post subject: The value of a column in the selected row of a table control |
|
|
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 |
|
 |
Decker87 OOo Enthusiast

Joined: 21 May 2007 Posts: 163
|
Posted: Wed Jul 18, 2007 7:41 am Post subject: |
|
|
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 |
|
 |
leeand00 General User

Joined: 01 Jul 2007 Posts: 24
|
Posted: Wed Jul 18, 2007 8:08 am Post subject: |
|
|
Thank you for being so diligent Decker!  |
|
| Back to top |
|
 |
Decker87 OOo Enthusiast

Joined: 21 May 2007 Posts: 163
|
Posted: Wed Jul 18, 2007 8:30 am Post subject: |
|
|
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 |
|
 |
leeand00 General User

Joined: 01 Jul 2007 Posts: 24
|
Posted: Wed Jul 18, 2007 8:52 am Post subject: |
|
|
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 |
|
 |
Decker87 OOo Enthusiast

Joined: 21 May 2007 Posts: 163
|
Posted: Wed Jul 18, 2007 10:37 am Post subject: |
|
|
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 |
|
 |
leeand00 General User

Joined: 01 Jul 2007 Posts: 24
|
Posted: Wed Jul 18, 2007 10:44 am Post subject: |
|
|
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 |
|
 |
|