Populating a component table from another table click event

I have two table components on a window (tblCellar,tblChosen). One is populated from a database. The other one table I want to populate as the user clicks on rows from the first table. I have the following:

if event.clickCount == 2:
    row = event.source.selectedRow
    table = event.source.parent.getComponent('tblCellar')
    ID = table.data.getValueAt(row,0)
    fermenter = table.data.getValueAt(row,3)

so that I have the values for ID and fermenter that were selected. I want to add these or append them to the table tblChosen.

On startup tblChosen is empty, but as the user selectes the fermenters he wants to work on, he can add them to the table and keep building up the list.

Building up new datasets in scripting isn’t very intuitive, but its not that hard. Here’s a script to get you rolling. The basic idea is that you copy out any existing information in the dataset to a python list, and then append information into that list, and then you use fpmi.db.ToDataSet() to convert it all back into a dataset. I’m going to assume that tblCellar’s datatset has two columns - ID and Fermenter.

[code]if event.clickCount == 2:
row = event.source.selectedRow
table = event.source.parent.getComponent(‘tblCellar’)
ID = table.data.getValueAt(row,0)
fermenter = table.data.getValueAt(row,3)

headers = ["ID", "Fermenter"]
data = []

# Copy existing data into the data list
existingDataSet = fpmi.db.toPyDataSet(table.data)
for row in existingDataSet:
    data.append([row[0], row[1]])

# Append the new row
data.append([ID, fermenter])
# Put the data back into tblCellar
table.data = fpmi.db.toDataSet(headers, data)[/code]

Hope this helps,

Works perfect!!! Thanks so much.

No problem.