Reputation: 11
How can I get the value of a selected item from a grid and put this into a textbox? Thanks!
Upvotes: 1
Views: 5741
Reputation: 4905
Try This as example and see if it works:
THISFORM.TEXT1.VALUE = THISFORM.GRID1.COLUMN1.TEXT1.VALUE
Upvotes: 0
Reputation: 3937
In a grid, moving to a row moves the record pointer to the corresponding row of the underlying table. So you just need to reference the appropriate item of the table.
ThisForm.Text1.Value = TheRelevantTable.TheRelevantField
Tamar
Upvotes: 0
Reputation: 48139
You can use the AfterRowColChange() event to preserve the latest "ControlSource" as bound to the grid. Then, on whatever basis you want to GET the value and put elsewhere, do an EVALUATE() of that source. To see a sample of this, I've created a simple form with a grid and a label. Grid column count set to -1 which by default auto-builds columns for all columns in the table/cursor used for the display.
As I scroll up/down, left/right between rows and columns, I am just getting the control source of whatever column I'm in, then setting the label's caption to the EVALUATION of such source. The "TRANSFORM()" forces the value into a string compatible so you won't crash out on logical, date, date/time, int, numeric, etc... You may have an issue on "General" type fields though.
LPARAMETERS nColIndex
lcSrc = This.Columns[nColIndex].ControlSource
Thisform.label1.Caption = TRANSFORM( EVALUATE( lcSrc ))
Again, to just preserve, you may want to store in the grid's "COMMENT" property as the "Last Column Having Focus"... (much like I did the lcSrc from above), then assign to whatever as needed from my assignment to the label. This way, you know which WAS the latest column at the time it DID have focus...
This.Comment = This.Columns[nColIndex].ControlSource
Upvotes: 1
Reputation: 917
From memory if the data source is a table or cursor I think the grid changes the current row on the table. So just access the table.
But I'm on holiday and on my iPhone so I'm going by memory.
Upvotes: 0