# Displaying a selected cell in a text field in Vision

**URL:** <https://forum.inductiveautomation.com/t/displaying-a-selected-cell-in-a-text-field-in-vision/61947>\
**Category:** Ignition\
**Tags:** vision, scripting\
**Created:** [July 15, 2022, 2:31pm UTC](https://forum.inductiveautomation.com/t/displaying-a-selected-cell-in-a-text-field-in-vision/61947 "2022-07-15T14:31:21Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![joseph.hahn](https://avatars.discourse-cdn.com/v4/letter/j/4da419/32.png) [@joseph.hahn](https://forum.inductiveautomation.com/u/joseph.hahn)\
**Post date:** [July 15, 2022, 2:31pm UTC](https://forum.inductiveautomation.com/t/displaying-a-selected-cell-in-a-text-field-in-vision/61947/1 "2022-07-15T14:31:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [July 15, 2022, 3:33pm UTC](https://forum.inductiveautomation.com/t/displaying-a-selected-cell-in-a-text-field-in-vision/61947/2 "2022-07-15T15:33:32Z")

</div>

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

```auto
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.

---

<div class="post-metadata">

**Author:** ![joseph.hahn](https://avatars.discourse-cdn.com/v4/letter/j/4da419/32.png) [@joseph.hahn](https://forum.inductiveautomation.com/u/joseph.hahn)\
**Post date:** [July 15, 2022, 3:42pm UTC](https://forum.inductiveautomation.com/t/displaying-a-selected-cell-in-a-text-field-in-vision/61947/3 "2022-07-15T15:42:13Z")

</div>

> [@pturmel](#):
>
> `try({Root Container.Power Table.data}[{Root Container.Power Table.selectedRow},{Root Container.Power Table.selectedColumn}], "")`

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?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [July 15, 2022, 3:45pm UTC](https://forum.inductiveautomation.com/t/displaying-a-selected-cell-in-a-text-field-in-vision/61947/4 "2022-07-15T15:45:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![joseph.hahn](https://avatars.discourse-cdn.com/v4/letter/j/4da419/32.png) [@joseph.hahn](https://forum.inductiveautomation.com/u/joseph.hahn)\
**Post date:** [July 15, 2022, 3:58pm UTC](https://forum.inductiveautomation.com/t/displaying-a-selected-cell-in-a-text-field-in-vision/61947/5 "2022-07-15T15:58:08Z")

</div>

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!"

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [July 15, 2022, 4:05pm UTC](https://forum.inductiveautomation.com/t/displaying-a-selected-cell-in-a-text-field-in-vision/61947/6 "2022-07-15T16:05:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![joseph.hahn](https://avatars.discourse-cdn.com/v4/letter/j/4da419/32.png) [@joseph.hahn](https://forum.inductiveautomation.com/u/joseph.hahn)\
**Post date:** [July 15, 2022, 4:09pm UTC](https://forum.inductiveautomation.com/t/displaying-a-selected-cell-in-a-text-field-in-vision/61947/7 "2022-07-15T16:09:26Z")

</div>

\</\> 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!”

---

<div class="post-metadata">

**Author:** ![craigb](https://avatars.discourse-cdn.com/v4/letter/c/9f8e36/32.png) [@craigb](https://forum.inductiveautomation.com/u/craigb)\
**Post date:** [July 15, 2022, 4:11pm UTC](https://forum.inductiveautomation.com/t/displaying-a-selected-cell-in-a-text-field-in-vision/61947/8 "2022-07-15T16:11:47Z")

</div>

On your table create a custom property with Phils code.

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

```

On your button do the below…

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/2/821cbc41d4f85406087f684a338aa1b56d3874a2.png)

---

<div class="post-metadata">

**Author:** ![joseph.hahn](https://avatars.discourse-cdn.com/v4/letter/j/4da419/32.png) [@joseph.hahn](https://forum.inductiveautomation.com/u/joseph.hahn)\
**Post date:** [July 15, 2022, 4:16pm UTC](https://forum.inductiveautomation.com/t/displaying-a-selected-cell-in-a-text-field-in-vision/61947/9 "2022-07-15T16:16:56Z")

</div>

> [@craigb](#):
>
> `try({Root Container.Power Table.data}[{Root Container.Power Table.selectedRow},{Root Container.Power Table.selectedColumn}], "")`

Worked great thanks a lot!

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [July 15, 2022, 4:20pm UTC](https://forum.inductiveautomation.com/t/displaying-a-selected-cell-in-a-text-field-in-vision/61947/10 "2022-07-15T16:20:12Z")

</div>

> [@joseph.hahn](#):
>
> \</\> Grab a reference to the table.\</\>

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.

```auto
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.

---

<div class="post-metadata">

**Author:** ![craigb](https://avatars.discourse-cdn.com/v4/letter/c/9f8e36/32.png) [@craigb](https://forum.inductiveautomation.com/u/craigb)\
**Post date:** [July 15, 2022, 4:37pm UTC](https://forum.inductiveautomation.com/t/displaying-a-selected-cell-in-a-text-field-in-vision/61947/11 "2022-07-15T16:37:17Z")

</div>

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

```auto
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

```

---

<div class="post-metadata">

**Author:** ![joseph.hahn](https://avatars.discourse-cdn.com/v4/letter/j/4da419/32.png) [@joseph.hahn](https://forum.inductiveautomation.com/u/joseph.hahn)\
**Post date:** [July 19, 2022, 3:20pm UTC](https://forum.inductiveautomation.com/t/displaying-a-selected-cell-in-a-text-field-in-vision/61947/12 "2022-07-19T15:20:25Z")

</div>

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/e/8edcac63e08361a787f48fb27d25e14a83305722.png)  
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?

---

<div class="post-metadata">

**Author:** ![craigb](https://avatars.discourse-cdn.com/v4/letter/c/9f8e36/32.png) [@craigb](https://forum.inductiveautomation.com/u/craigb)\
**Post date:** [July 19, 2022, 9:10pm UTC](https://forum.inductiveautomation.com/t/displaying-a-selected-cell-in-a-text-field-in-vision/61947/13 "2022-07-19T21:10:47Z")

</div>

You new table is a table in your database ?

On your button…

```auto
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)

```

---

<div class="post-metadata">

**Author:** ![Priyanka.Khandge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/priyanka.khandge/32/35989_2.png) [@Priyanka.Khandge](https://forum.inductiveautomation.com/u/Priyanka.Khandge)\
**Post date:** [November 28, 2022, 11:18am UTC](https://forum.inductiveautomation.com/t/displaying-a-selected-cell-in-a-text-field-in-vision/61947/14 "2022-11-28T11:18:49Z")

</div>

Worked Great..Thanks a lot.

---

<div class="post-metadata">

**Author:** ![JVDM](https://avatars.discourse-cdn.com/v4/letter/j/ac8455/32.png) [@JVDM](https://forum.inductiveautomation.com/u/JVDM)\
**Post date:** [July 16, 2025, 7:29am UTC](https://forum.inductiveautomation.com/t/displaying-a-selected-cell-in-a-text-field-in-vision/61947/15 "2025-07-16T07:29:58Z")

</div>

Great solution. Helped me out as well. Thank you.
