Getting a list of contents of a Group

I am trying the following:
I have grouped together 3 checkboxes (and I intend to add many more checkboxes into this group). Users will be selecting one or more of these checkboxes. Based on their selection, I need to be able to obtain the name of the selected checkboxes.

For example, a user has selected 2 of the 3 checkboxes as shown in the attached picture. So, by a click of a button, I need to be able to get the names – ‘ActualRotationSpeed’ and ‘StepNumber’ printed on the output. What script can I write for that button to achieve that?

I need something like this – but don’t know the actual syntax -
For each row in event.source.parent.getComponent(‘Group’).name:
Print name of the Checkbox

Also, I want to create ‘Select All’ and ‘Deselect All’ buttons so that users can select or deselect all the checkboxes at the same time. What script can I use for these two buttons to achieve that?

you may be better off using a table component for what you want to do. you could easily do what you want using the table component. you can run thru the dataset to grab which ones are selected easily and also select/deselect all.

Thank you very much! I tried the table component. I was able to get the names – ‘ActualRotationSpeed’ and ‘StepNumber’ printed on the output using the following code:
selectiondata = event.source.parent.getComponent(‘Selection Table’).data
selectionrows = event.source.parent.getComponent(‘Selection Table’).selectedRows
count = len(selectionrows)
for row in range(selectiondata.rowCount):
for i in range(len(selectionrows)):
if selectiondata.getValueAt(row, “Selection”) == 1:
print selectiondata.getValueAt(row, “Trace”)

However, I am running into a problem when I create the Select All button. I use the following code for that:
selectiondata = event.source.parent.getComponent(‘Selection Table’).data
for row in range(selectiondata.rowCount):
selectiondata.setValue(row,“Selection”,1)

I am hoping that the setValue function will assign a value of 1 (i.e. True) for all the rows - making all of them ‘selected’. But I get an error message attached in the screen capture

What function can I use if setValue is not a valid function?

This is how I did this the other day. My username, email comes from my database, but I create the selected column. same principle, just slightly different…

This would be when the screen loads and if someone clicks the clear all button

res = system.db.runQuery("SELECT username, email from users order by username")
header = ["Username", "Email", "Selected"]
newData = []

for row in res:
	newData.append([row[0], row[1], False])
	


event.source.parent.getComponent('Table').data = system.dataset.toDataSet(header, newData)

This would be to select all

res = system.db.runQuery("SELECT username, email from users order by username")
header = ["Username", "Email", "Selected"]
newData = []

for row in res:
	newData.append([row[0], row[1], True])
	


event.source.parent.getComponent('Table').data = system.dataset.toDataSet(header, newData)

Here is a sample of print the selected columns

emailDS = system.dataset.toPyDataSet(event.source.parent.getComponent('Table').data)
emailList = []
for row in emailDS:
	if row[2] == True:
		print row[1] + ' Selected'

also, you can turn off the border, header and horizontal/vertical lines on the table component and change the background/row selection color to match your window background. Like that, you wont be able to tell the difference between the table and the check box component.

Since setValue is a method of the table, you could try:

selection = event.source.parent.getComponent("Selection Table")
for row in range(selection.data.rowCount):
	selection.setValue(row, 0, 1)
	

Thank you very much! I tried this code suggested by adamaustin and it worked perfectly for me.

selection = event.source.parent.getComponent(“Selection Table”)
for row in range(selection.data.rowCount):
selection.setValue(row, 0, 1)

Thanks!

Shreyas

To do this with a script in a button, you can to the following:

I made a group in the Root Container called Group and it has three CheckBox components

Select all button

group = event.source.parent.getComponent('Group').components
for components in group:
	components.selected = 1			#set selected to true (select all checkboxes)

Deselect all button

group = event.source.parent.getComponent('Group').components
for components in group:
	components.selected = 0			#set selected to false (deselect all checkboxes)

Button to print the names of only the selected checkboxes

group = event.source.parent.getComponent('Group').components
for components in group:
	if components.selected == True:
		print components.name     #name of the CheckBox component in the Project Browser
		#print components.text        #name of the CheckBox as it shows where they check or uncheck boxes

How could I do this same thing but with Radio Buttons?

You don’t need to. This question is about check boxes of which operate independently so multiple values can be on at once. You are asking about radio buttons and this has been addressed in answers to your other question, Radio Button Group Selected - #10 by Ros_Alexander.

1 Like