Reputation: 35
I'm working with a grid that allows selection. I have a variable whose Control Type is Check Box.
I want to enable a button if at least one row is selected, otherwise the button should be disable.
To achieve this I'm using the event "Click" of the CheckBox variable.
How can I get the number of selected rows? Thanks in advance.
Environment: (C# Web) GeneXus X Evolution 2 Version: 10.2.54798
Upvotes: 0
Views: 3369
Reputation: 31
you can also do
Event Refesh
&count = 0
for each line in Grid
if Checkbox
&count += 1
endif
endfor
Button.enabled = (&count > 0)
EndEvent
Also, if you dont actually care how many lines selected and you only want to know if there is at least one, you can put an exit when you enter the if Checkbox condition and instead of a &count variable you can just have a boolean &haveRowSelected, like this:
Event Refesh
&haveRowSelected = false
for each line in Grid
if Checkbox
&haveRowSelected = true
exit
endif
endfor
Button.enabled = haveRowSelected
EndEvent
Hope it helps.
Upvotes: 0
Reputation: 455
Try this:
Event Refresh
&count = 0
EndEvent
Event Checkbox.Click
if Checkbox = true
&count += 1
else
&count -= 1
endif
if &count > 0
Button.enabled = 1
else
Button.enabled = 0
endif
EndEvent
In this sample &count
has the number of selected rows.
Upvotes: 3