How to select and de-select checkboxes in a Table, using a button?

Product: PowerShell Universal
Version: 2.6.2

Hey everyone,

I have a table using New-UDTable with -ShowSelection, so it creates checkboxes for each row. Further down into the coding I have a button that takes actions on each row for the .SelectedRows of Get-UDElement -ID ‘tableId’. Once all actions are complete, I refresh the table and remove the selected rows from it.

With this setup if one or more actions fail, those rows are removed during the refresh; along with the ones that have successful actions completed.

I’m trying to figure out how I can de-select a row from the table, when an action for it fails. If an action fails, I want to de-select that row from the table, before table refresh actions are taken to remove all the selected rows.

Anyone know how to select and de-select checkboxes in a table, that were created with -ShowSelection? Any code examples for doing this with a button?

Thanks,
Rob

I’m not sure, but this would be an interesting one to find out.
I used to do something similar in UD v2 back before checkboxes were part of the tables.
I basically made my own column with checkboxes in, so had ID’s to refer to.
I then had a button at the top of my page for ‘select all’ and ‘clear all’.

But it would be useful to know if we can interact in the same way with V3 tables and their integrated checkboxes… I’ll have a playaround with it at some point and update if I work it out.

I ended up implementing a workaround, similar to what you described, here: https://forums.ironmansoftware.com/t/get-and-set-udelement-on-a-textbox-that-is-in-a-hidden-table-column/6363/2

Doing this workaround involved disabling the textbox in a row that successfully processes, and leaving the textbox enabled on failure. On refreshing the UDDynamic the table’s wrapped in, I loop through the selected rows and remove those with a textbox still enabled. This removes those that failed processing, and leaves me with a list of VM Names that are no longer needed in the table. I then list all the rows in the table, grab their VM Name, and filter out the ones we no longer need. Then I lookup the remaining VMs in VMware, create new objects, and then re-create the table with only the remaining VMs to work with.

Some of this convoluted process could be eliminated if we can find a way to select/de-select the checkboxes in a table using -ShowSelection. I tried for 2 days before posting this question…LOL

The entire convoluted process could be eliminated if we could do 2 things:

  1. Select/De-Select the checkboxes in a table using -ShowSelection
    a. When processing actions for selected rows, we can take an action to de-select a row on failure; using Try/Catch.

  2. Have a simple way to remove selected rows from the table:
    a. If we perhaps had a command to remove the selected rows, we wouldn’t need to wrap a lot of stuff into a UDDynamic and do table refreshes by calling Sync-UDElement on the UDDynamic ID.
    b. Maybe something like Sync-UDTable -Id ‘table-id’ -RemoveSelectedRows
    c. Just tossing that out there :wink:

Thanks,
Rob