# Programmatically Set Selected Cell in Power Table

**URL:** <https://forum.inductiveautomation.com/t/programmatically-set-selected-cell-in-power-table/21749>\
**Category:** Ignition\
**Created:** [January 8, 2019, 6:44pm UTC](https://forum.inductiveautomation.com/t/programmatically-set-selected-cell-in-power-table/21749 "2019-01-08T18:44:05Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [January 8, 2019, 6:44pm UTC](https://forum.inductiveautomation.com/t/programmatically-set-selected-cell-in-power-table/21749/1 "2019-01-08T18:44:05Z")

</div>

I’m trying to set a cell to being selected with programming. I’ve tried using the below code and many variations to no avail.  
I’ve also tried to bind the Selected Column and Selected Row properties to a value, but it doesn’t work.

```auto
t = event.source.parent.getComponent("Power Table")getTable() 
t.addSelectionInterval(1,1) 

```

I’ve also tried this within a button:

```auto
event.source.parent.getComponent('Power Table').selectedRow = 1
event.source.parent.getComponent('Power Table').selectedColumn = 1

```

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [January 8, 2019, 6:57pm UTC](https://forum.inductiveautomation.com/t/programmatically-set-selected-cell-in-power-table/21749/2 "2019-01-08T18:57:27Z")

</div>

Some code that I used on a personal project:

```auto
target = self.parent.parent.getComponent("Data")
ds = target.viewDataset
for row in range(ds.rowCount):
	if ds.getValueAt(row, 0) == time:
		target.getTable().getSelectionModel().setSelectionInterval(row, row)
		target.getTable().scrollRowToVisible(row)
		break

```

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [January 8, 2019, 7:10pm UTC](https://forum.inductiveautomation.com/t/programmatically-set-selected-cell-in-power-table/21749/3 "2019-01-08T19:10:10Z")

</div>

I follow the logic, but not sure how to re-appropriate it to fit my needs. I have two custom properties on my table, and I want the selected column and selected row to reflect those. Why are the selected column and selected row properties bindable, but it doesn’t do anything when bound? I tried this on a button and it did not do anything

```auto
target = event.source.parent.getComponent('Power Table')
target.getTable().getSelectionModel().setSelectionInterval(1, 1)
target.getTable().scrollRowToVisible(1)

```

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [January 8, 2019, 7:22pm UTC](https://forum.inductiveautomation.com/t/programmatically-set-selected-cell-in-power-table/21749/4 "2019-01-08T19:22:17Z")

</div>

They’re bindable only because any integer property is ‘bindable’, even if setting it will not reflect changes back. Sending changes back to the table is more complicated because of the potential for conflicts between a ‘model’ and a ‘view’ index, further complicated by things like sorting and filtering.

I’m not sure why your test code isn’t working - does your power table match these settings?:

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [January 8, 2019, 7:27pm UTC](https://forum.inductiveautomation.com/t/programmatically-set-selected-cell-in-power-table/21749/5 "2019-01-08T19:27:24Z")

</div>

Sure does, no luck. Let me try a different method… How can I pull in my custom properties on the table (rowRef and colRef) into the configure cell function, and make it look like it is selected? This is really just to reflect the row and column pointers anyways.

EDIT: That test code did work on selecting a row I thought the row selection was allowed but it was unchecked. Now how to select a single cell…

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [January 8, 2019, 7:37pm UTC](https://forum.inductiveautomation.com/t/programmatically-set-selected-cell-in-power-table/21749/6 "2019-01-08T19:37:03Z")

</div>

To select a single cell, make sure you have column selection allowed, then set a specific row and column interval:  
[https://docs.oracle.com/javase/7/docs/api/javax/swing/JTable.html#setRowSelectionInterval(int,%20int)](https://docs.oracle.com/javase/7/docs/api/javax/swing/JTable.html#setRowSelectionInterval(int,%20int))  
[https://docs.oracle.com/javase/7/docs/api/javax/swing/JTable.html#setColumnSelectionInterval(int,%20int)](https://docs.oracle.com/javase/7/docs/api/javax/swing/JTable.html#setColumnSelectionInterval(int,%20int))

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [January 8, 2019, 8:01pm UTC](https://forum.inductiveautomation.com/t/programmatically-set-selected-cell-in-power-table/21749/9 "2019-01-08T20:01:18Z")

</div>

HA!! Got it

```auto
target = event.source.parent.getComponent('Power Table')
target.getTable().changeSelection(1,1,0,0)

```

this selects cell 1,1

 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/0/04a79553ee8eb0ecce7c2455e6bc608e3cdfba42.png)

---

<div class="post-metadata">

**Author:** ![epifanio.tigno](https://avatars.discourse-cdn.com/v4/letter/e/57b2e6/32.png) [@epifanio.tigno](https://forum.inductiveautomation.com/u/epifanio.tigno)\
**Post date:** [March 18, 2021, 8:23am UTC](https://forum.inductiveautomation.com/t/programmatically-set-selected-cell-in-power-table/21749/10 "2021-03-18T08:23:55Z")

</div>

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

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

table.setSelectedRow(initialselRow + 1)

this will select row downwards

---

<div class="post-metadata">

**Author:** ![jasoncoope](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jasoncoope/32/18674_2.png) [@jasoncoope](https://forum.inductiveautomation.com/u/jasoncoope)\
**Post date:** [April 6, 2021, 9:58pm UTC](https://forum.inductiveautomation.com/t/programmatically-set-selected-cell-in-power-table/21749/11 "2021-04-06T21:58:29Z")

</div>

Have noticed that to use the onRowsDropped feature to drag a row from one table to another, you have to first select the row by clicking on it, release it so it is added to the selectedRows and then click on the same row again to drag it. Doesn’t seem like a big deal, but the schedulers keep saying they can’t drag work orders on the schedule table. I was hoping I could use the above logic to add to the selected rows in the onMousePressed() extension function, but it doesn’t seem to update whatever object is needed for the onRowsDropped to work on the other table.

How can I make onRowsDropped work with a single click and drag?
