# Setting Selected Row and Column on Table Right Click

**URL:** <https://forum.inductiveautomation.com/t/setting-selected-row-and-column-on-table-right-click/2455>\
**Category:** Ignition\
**Created:** [December 27, 2010, 6:39am UTC](https://forum.inductiveautomation.com/t/setting-selected-row-and-column-on-table-right-click/2455 "2010-12-27T06:39:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kyle\_Chase](https://avatars.discourse-cdn.com/v4/letter/k/9de0a6/32.png) [@Kyle\_Chase](https://forum.inductiveautomation.com/u/Kyle_Chase)\
**Post date:** [December 27, 2010, 6:39am UTC](https://forum.inductiveautomation.com/t/setting-selected-row-and-column-on-table-right-click/2455/1 "2010-12-27T06:39:07Z")

</div>

On a table, with a left click, it will change the selected column and row. However, it does not do this with a right click. Here is the code to enable this. You will but this in event mouse click script.

[code]#Get the current viewport of the JScrollPane(the Component that holds the table)  
view = event.source.viewport  
#Get the current view position. This is in relation to top right hand corner of the component)  
position = view.getViewPosition()

#Find the row that was selected. We subtract 17 as that is the height of the header  
row = int((event.y-17+position.getY())/event.source.rowHeight)  
#Set event.source.selectedRow to the row selected  
event.source.selectedRow = row

#Get the Column Model of the table itself. Because there is only one component in the view, we use index 0  
columnModel = view.getComponent(0).getColumnModel()  
#Get the index of the column we selected  
column = columnModel.getColumnIndexAtX(int(event.x+position.getX()))  
#Set event.source.selectedColumn to the column selected  
event.source.selectedColumn = column  
[/code]

---

<div class="post-metadata">

**Author:** ![nmudge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nmudge/32/3394_2.png) [@nmudge](https://forum.inductiveautomation.com/u/nmudge)\
**Post date:** [August 19, 2011, 8:00pm UTC](https://forum.inductiveautomation.com/t/setting-selected-row-and-column-on-table-right-click/2455/2 "2011-08-19T20:00:16Z")

</div>

Here’s a different way to do the same thing:

[code]from java.awt import MouseInfo, Point  
table = event.source  
#get the mouse pointer location on the computer monitor  
p = MouseInfo.getPointerInfo().getLocation()  
#get the mouse pointer location relative to the Ignition application  
mousex = p.x - table.getTable().getLocationOnScreen().x  
mousey = p.y - table.getTable().getLocationOnScreen().y  
mousep = Point(mousex,mousey)

#get the cellRow and cellCol and set them in the table  
cellCol = table.getTable().columnAtPoint(mousep)  
cellRow = table.getTable().rowAtPoint(mousep)  
table.getTable().addColumnSelectionInterval(cellCol, cellCol)  
table.getTable().addRowSelectionInterval(cellRow,cellRow)[/code]This goes in the mouseClicked event script on the table.
