[Gambas-user] Check Boxes (a bug?)

John Dovey dovey.john at gmail.com
Fri Jun 11 19:20:02 CEST 2021


Thank you, That's helpful.
Now to make it work...

Just one quick comment. I pasted your code with the "CheckBoxGroup_Click()"
subroutine, but I named the group 'AflagsGroup". It took me a few minutes
to figure out why it wasn't working. There was no error that there was no
such event :-)


[image: image.png]



On Fri, 11 Jun 2021 at 07:57, T Lee Davidson <t.lee.davidson at gmail.com>
wrote:

> On 6/11/21 4:33 AM, Bruce Steers wrote:
> > To stop click events triggering try something like this...
> >
> > Object.Lock(ChkAflag_CM)
> >   ChkAflag_CM.Value = myAflag_CM
> > Object.UnLock(ChkAflag_CM)
> >
>
> That's one way to skin a cat.
>
> There is also another solution that, although a bit more involved, could,
> IMO, simplify the code somewhat. I don't have time at
> the moment to present full example code, but it involves the following
> principles.
>
> 1. Controls can be grouped. If the checkboxes are given the group, say,
> CheckBoxGroup, then a single event handler
> (CheckBoxGroup_Click) could be used for all four.
>
> 2. Within that single event handler, the Last keyword can be used as a
> reference to the control that triggered the handler. The
> value of the checkbox that changed would then be accessed with Last.Value.
>
> 3. The Settings component can store a Collection. For example, define the
> defaults as follows:
> Public myAflags as Collection = ["CM": true, "MO": false, "LO": false,
> "ICM": false]
> And, change the code to store and retrieve the flags as a collection
> instead of individual variables.
>
> 4. Controls have a Tag property. This could be used to tag the individual
> checkboxes with the appropriate string, ie, "MO",
> "CM", etc.
>
> Using these principles, all that would be needed to be done in the event
> handler is:
> Public Sub CheckBoxGroup_Click()
>    Dim myAflagsString as String[]
>
>    myAflags[Last.Tag] = Last.Value ' We set the value only on the flag
> that changed and do not mess with the others.
>    For Each myFlag as String in myAflags
>      If myFlag Then
>        myAflagsString.Add(myAflags.Key)
>      End If
>    Next
>    LblAflags.Text = myAflagsString.Join(",")
> End
>
> I may have missed a few things and have not tested that code.
>
>
> --
> Lee
>
> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20210611/af9c4184/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 44015 bytes
Desc: not available
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20210611/af9c4184/attachment-0001.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: proj.tar.gz
Type: application/x-gzip
Size: 4885 bytes
Desc: not available
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20210611/af9c4184/attachment-0001.bin>


More information about the User mailing list