# Selecting a cell from a table

**URL:** <https://forum.inductiveautomation.com/t/selecting-a-cell-from-a-table/12178>\
**Category:** Ignition\
**Created:** [September 27, 2016, 9:12pm UTC](https://forum.inductiveautomation.com/t/selecting-a-cell-from-a-table/12178 "2016-09-27T21:12:53Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mr.K001](https://avatars.discourse-cdn.com/v4/letter/m/ea5d25/32.png) [@Mr.K001](https://forum.inductiveautomation.com/u/Mr.K001)\
**Post date:** [September 27, 2016, 9:12pm UTC](https://forum.inductiveautomation.com/t/selecting-a-cell-from-a-table/12178/1 "2016-09-27T21:12:53Z")

</div>

Hey everyone, I have this so far:

```auto
table = event.source.parent.getComponent('Table')
textField = event.source.parent.getComponent('Label')
value = table.data
textField.text = value.getValueAt(table.selectedRow,table.selectedColumn)
system.tag.write("TESTT",textField.text)
```

I basically want the operator to be able to select a cell from a table and enter some data and when submitted that selected value gets used in the WHERE clause so the data can be inserted in the correct row.  
I want the first column selected and what I have lets me do that, my issue is if I click on any other column I get an error saying

```auto
Traceback (most recent call last):

  File "<event:mouseClicked>", line 4, in <module>

TypeError: can't convert 96 to java.lang.String
```

96 happened to be a value in that specific cell. I even tried another cell that is a time stamp just like the first row but got the same error. I would like to click on any cell and basically get the value of the first column of that row. I was also testing with writing to a tag facing the same problem.  
I’d appreciate all the help. Thanks

---

<div class="post-metadata">

**Author:** ![JGJohnson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jgjohnson/32/29582_2.png) [@JGJohnson](https://forum.inductiveautomation.com/u/JGJohnson)\
**Post date:** [September 27, 2016, 9:34pm UTC](https://forum.inductiveautomation.com/t/selecting-a-cell-from-a-table/12178/2 "2016-09-27T21:34:10Z")

</div>

The values in the other columns that you mention are of a different type (not strings).

A quick way to handle the issue is to cast the value to the string data type.

`
textField.text = str(value.getValueAt(table.selectedRow,table.selectedColumn))`

---

<div class="post-metadata">

**Author:** ![Mr.K001](https://avatars.discourse-cdn.com/v4/letter/m/ea5d25/32.png) [@Mr.K001](https://forum.inductiveautomation.com/u/Mr.K001)\
**Post date:** [September 28, 2016, 12:25pm UTC](https://forum.inductiveautomation.com/t/selecting-a-cell-from-a-table/12178/3 "2016-09-28T12:25:55Z")

</div>

[quote=“JGJohnson”]The values in the other columns that you mention are of a different type (not strings).

A quick way to handle the issue is to cast the value to the string data type.

`
textField.text = str(value.getValueAt(table.selectedRow,table.selectedColumn))`[/quote]

Thank you JGJohnson, that certainly fixed the issue with the error. How would I approach the other issue as far as only the first column value of a row being selected whenever any column of that row is selected?  
could something be done here

```auto
getValueAt(table.selectedRow,table.selectedColumn)
```

perhaps something like selectedRow and 0 for selectedColumn so column 0 always get selected no matter what row you select.

---

<div class="post-metadata">

**Author:** ![Mr.K001](https://avatars.discourse-cdn.com/v4/letter/m/ea5d25/32.png) [@Mr.K001](https://forum.inductiveautomation.com/u/Mr.K001)\
**Post date:** [September 28, 2016, 12:33pm UTC](https://forum.inductiveautomation.com/t/selecting-a-cell-from-a-table/12178/4 "2016-09-28T12:33:40Z")

</div>

Wellll, never mind I had the right idea ` getValueAt(table.selectedRow,0) ` is exactly what i need to only get the first column of any row. ![:thumb_right:](https://us1.discourse-cdn.com/inductiveautomation/original/1X/2026e28c0c425034352c1b75807edf956adc75f4.gif ":thumb\_right:") ![:thumb_left:](https://us1.discourse-cdn.com/inductiveautomation/original/1X/e26afb081ddde6df016df6ee49159cf56aaca688.gif ":thumb\_left:")

---

<div class="post-metadata">

**Author:** ![JGJohnson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jgjohnson/32/29582_2.png) [@JGJohnson](https://forum.inductiveautomation.com/u/JGJohnson)\
**Post date:** [September 28, 2016, 12:44pm UTC](https://forum.inductiveautomation.com/t/selecting-a-cell-from-a-table/12178/5 "2016-09-28T12:44:51Z")

</div>

Yep. ![:thumb_left:](https://us1.discourse-cdn.com/inductiveautomation/original/1X/e26afb081ddde6df016df6ee49159cf56aaca688.gif ":thumb\_left:")

In that case you won’t need to cast the value to string. I missed the part in your post where you said that you wanted the 1st column to be selected.

Also keep in mind that you can reference the column by name. That will keep your script from breaking if you ever change the order of columns in the table.

```auto
text = getValueAt(table.selectedRow, "mySpecialColumn")
```

---

<div class="post-metadata">

**Author:** ![Mr.K001](https://avatars.discourse-cdn.com/v4/letter/m/ea5d25/32.png) [@Mr.K001](https://forum.inductiveautomation.com/u/Mr.K001)\
**Post date:** [September 28, 2016, 1:12pm UTC](https://forum.inductiveautomation.com/t/selecting-a-cell-from-a-table/12178/6 "2016-09-28T13:12:42Z")

</div>

that’s a good one to know thank you! ![:thumb_left:](https://us1.discourse-cdn.com/inductiveautomation/original/1X/e26afb081ddde6df016df6ee49159cf56aaca688.gif ":thumb\_left:")
