Selecting a cell from a table

Hey everyone, I have this so far:

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

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

1 Like

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

1 Like

[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

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.

1 Like

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: :thumb_left:

1 Like

Yep. :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.

text = getValueAt(table.selectedRow, "mySpecialColumn")
1 Like

that’s a good one to know thank you! :thumb_left:

1 Like