Hi all,
I have created a gallery which uses a collection as its data source, this collection is generated when the screen becomes visible as such - ClearCollect(Findings, {no:1}). I also have a button that creates additional rows in the collection - Patch(auditFindings, Defaults(Findings), {no:CountRows(Findings)+1). In the gallery, I have a field called reportnumber-00X whereby X is thisitem.no
The problem comes in when I try to delete the entry in the gallery (done through a button in the gallery with onSelect property of RemoveIf(Findings, no=thisitem.no) . I would like the field reportnumber-00X to update automatically. E.g. if i have reportnumber-001, reportnumber-002, reportnumber-003, reportnumber-004 and I delete reportnumber-002, the gallery should show reportnumber-001, reportnumber-002, reportnumber-003 instead of reportnumber-001, reportnumber-003, reportnumber-004. How can this be achieved? TIA!
Hi @ccqn ,
I have had to do something similar. This is how I achieved what you are trying to do:
1) In the OnVisible of a Screen, use:
ClearCollect(Findings, {no:1,Title:"Item1"})
2) Add a Gallery to the Screen and a "+" icon above it:
3) Set the Gallery Data Source to "Findings". Add two Labels to the Template for the Gallery and link them to the "no" value and the "Title" value.
4) For the "+" icon, set the OnSelect to:
Collect(Findings, {no:CountRows(Findings)+1, Title:"Item" & Text(CountRows(Findings)+1)})
5) In the Template for the Gallery, add a "Trash"can icon. Set the OnSelect to:
RemoveIf(
Findings,
no = ThisItem.no
);
ClearCollect(
Findings,
With(
{records: Findings},
ForAll(
Sequence(CountRows(records)),
Patch(
Last(
FirstN(
records,
Value
)
),
{no: Value}
)
)
)
);
With the example, you should now be able to add and delete items. The "no" field will update. See below:
The item with the Title "Item3" was deleted and the other items renumbered.
I pulled this example together using this article:
If I've answered your question or solved your problem, please mark this question as answered. This helps others who have the same question find a solution quickly via the forum search. If you liked my response, please consider giving it a thumbs up.
Thanks.
-Mark