Displaying a selected cell in a text field in Vision

I am trying to display a selected cell from a power table in a text field in vision. I have a script working to select a cell and a momentary push button to output it in the script console. How do I output this data in a text field? Thanks in advance

On the text field’s text property, try this expression binding:

try({Root Container.Power Table.data}[{Root Container.Power Table.selectedRow},{Root Container.Power Table.selectedColumn}], "")

The “try” delivers an empty string when no row/column is selected.

Thanks for the response this did work. Adding to that I have a momentary push button that outputs this cell data to the script console when pressed. How could I get this to all work together so that the selected cell is displayed after the button is pressed into the text field?

Instead of printing, assign to the text field’s text property.

What should the code look like?
Here is what I have:

Grab a reference to the table.

table = event.source.parent.getComponent(‘Power Table’)

Make sure the user selected something before doing the rest of the work.

if table.selectedRow != -1:

CastNumberSelected = table.data.getValueAt(table.selectedRow, "CurrentCastNumber")
 
# Do something with the Cast# variable.
print CastNumberSelected

else:
print “Please Select a Cast Number!”

{ Please edit your code comment to pre-format the code, using the </> button. }

</> Grab a reference to the table.</>
table = event.source.parent.getComponent(‘Power Table’)

</> Make sure the user selected something before doing the rest of the work.</>

if table.selectedRow != -1:

CastNumberSelected = table.data.getValueAt(table.selectedRow, "CurrentCastNumber")

</>Do something with the Cast# variable.</>
print CastNumberSelected
else:
print “Please Select a Cast Number!”

On your table create a custom property with Phils code.

try({Root Container.Power Table.data}[{Root Container.Power Table.selectedRow},{Root Container.Power Table.selectedColumn}], "")

On your button do the below…

Worked great thanks a lot!

No, what Phil is recommending that you do is,

  1. In the editor first select your code.
  2. Press the </> button. The result will be code formatted as shown below. There is something similar on almost every forum on the Internet.
if table.selectedRow != -1:
    CastNumberSelected = table.data.getValueAt(table.selectedRow, "CurrentCastNumber")
    # Do something with the Cast# variable.
    print CastNumberSelected
else:
    print “Please Select a Cast Number!”

You should also see a :ballot_box_with_check: solution button under every answer. You click this to show that your problem has been solved. You should do this on craigb’s answer which seems to have worked for you.

To go a step further, try this code on your button in the script editor.

value = event.source.parent.getComponent('Table').Value
	
if value == '':
	system.gui.messageBox("No value selected", "Error")
else:
	event.source.parent.getComponent('Text Field').text = value


To go a step further with this, how would I get the data out of the two text fields and populate them on another table as a two column row every time they hit the Enter cast info into table button?

You new table is a table in your database ?

On your button…

TextField1  = Path to text field value
TextField2 = Path to text field value
system.db.runPrepUpdate("INSERT INTO YourTable (Column1, Column 2) VALUES (?,?)", [TextField1, TextField2], DatabaseName)