Reputation: 13
I have a tableview and I want to open a dialog box on onPressAndHold on a row and display the value of the cell of the row "orderNumber". But i get the Error message: ReferenceError: row is not defined
TableView {
id: tableviewopenorders
height: 180
clip: false
visible: true
onPressAndHold: oocanceldialog.open()
TableViewColumn {
id: orderNumberColumn
role: "orderNumber"
title: "Order Number"
}
model: openordersModel
}
ListModel {
id: openordersModel
ListElement {
orderNumber: "1223455"
}
ListElement {
orderNumber: "111111"
}
}
Dialog {
id: oocanceldialog
title: "Cancel confirmation"
standardButtons: Dialog.Ok | Dialog.Cancel
x: (parent.width - width) / 2
y: (parent.height - height) / 2
Label {
text: openordersModel.get(row).orderNumber
}
onAccepted: console.log("Ok clicked")
onRejected: oocanceldialog.close()
}
Upvotes: 1
Views: 3118
Reputation: 243897
row
exists in the context of onPressAndHold
, so it does not exist outside of it, to get the row we must use the currentRow
attribute of the TableView
:
currentRow : int
The current row index of the view. The default value is -1 to indicate that no row is selected.
In your case:
Label {
text: openordersModel.get(tableviewopenorders.currentRow).orderNumber
}
Upvotes: 0