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,
- In the editor first select your code.
- 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 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)
Worked Great..Thanks a lot.