Highlighting the last row inserted into a table

I am generating a table dataset, i have a button that adds a new row. I would like to have this new row highlight once its inserted but its never on the top or bottom of the list.

What would be the best way to highlight the last inserted row into the table? I do have the ID that I insert into the table but i don’t see how I can find or search the dataset to select that specific row.

Any suggestions would be great, thanks!


Id probably add another column and put a 1 in it, then do a background color based off of that new column. You would just have to make sure and go set the previous column that had a 1 to 0.

I might just pull the data out of the dataset, parse it and find the ID that was inserted, get the number of the row and then make that the highlighted row.

I’ll let you know what i find


Hi drewdin,

By highlighted, do you mean having the row selected? Or do you mean having the background color of the row changed?

Nick Mudge
Ignition Consulting

I am just trying to highlight the newly inserted row, What i have works but there is a timing issue between the row being inserted and the data in the table updating.

I am always behind by the row inserted, it shows in the table but my script does not show the inserted row.

Any suggestions? Thanks again

There are two ways to highlight a row. By making a row the currently selected row, or by changing the background color of a row. Which do you want? Or is either fine?

Is it correct that the table has an ID column that uniquely identifies each row? When a new row is inserted do you also get the ID of the newly inserted row? Or do you need to check the table for a new ID?

You are correct, I am inserting a row into a DB, getting the key back from the insert. The first column of my table has this ID.

I’m looping through the table dataset, looking at column 0 for the ID that was just inserted. When the script ends, no rows are highlighted but i can see the new row in the table. I am printing out each row and i don’t see the recently inserted ID.

I am doing a data refresh of the table and a 1 sec delay before my iteration and i still cant see it.

Thanks for the details.

I implemented a solution that works.

I added a custom property called ID on a table.

I have a button that when pressed does a database insert and assigns the unique ID of the new record to the table’s ID property. So the actionPerformed script on the button looks like this:

query = "INSERT INTO Line (ParentID,Name,TimeStamp) VALUES (?,?,NOW())"
id = system.db.runPrepUpdate(query, [4,"test"], getKey=True)
event.source.parent.getComponent('Table').ID = id

The table has a database binding to the Line database table. The query is automatically refreshed every 5 seconds.

I added the following propertyChange script to the table:

if event.propertyName == "data":
	for i in range(event.source.data.rowCount):
		if event.source.data.getValueAt(i,"ID") == event.source.ID:
			event.source.selectedRow = i

When the button is clicked a new record is inserted and within 5 seconds the table is updated with the new row and it instantly becomes highlighted.

Nick Mudge
Ignition Consultant

that worked great, thanks for the help!