Lazarus

Programming => LCL => Topic started by: mijen67 on October 07, 2017, 11:38:33 pm

Title: Stringgrid checkbox with select-only-one functionality
Post by: mijen67 on October 07, 2017, 11:38:33 pm
I'm using a stringgrid with a column defined as a checkbox (by setting ButtonStyle=cbsCheckboxColumn, ValueChecked and ValueUnchecked are default i.e. 1 and 0; and finally option GoEditing is true so that user can toggle each checkbox-cell).

In the application I sometimes need to allow multiple rows to be selected (by checking checkbox) and in other cases I need to request user to only select one row. In the latter case when user clicks on one rows checkbox all other rows should be set to unchecked. Is there an elegant way to accomplish this? Or should the functionality be programmed "manually"?

Kind regards,
Michael
Title: Re: Stringgrid checkbox with select-only-one functionality
Post by: taazz on October 08, 2017, 01:07:51 am
1) doesn't stringgrid support multiselect? (haven't used for so long I can't remember)
2)to code a multi select ability you create a list of selected rows when the user checks the box you add the row to the list when the boxgets uncheckd you remove the row from the list. you do not keep the state of the selection in the grid / data you simple paint a checked box if the row is in the checked list, otherwise you paint an unchecked box. That is in my experience the less prone to errors method.
Title: Re: Stringgrid checkbox with select-only-one functionality
Post by: jamie on October 08, 2017, 01:12:29 am
The OnCheckBoxToggled event is the best place to handle that. Then manually
select the items you want.
Title: Re: Stringgrid checkbox with select-only-one functionality
Post by: mijen67 on October 14, 2017, 07:58:41 pm
1) doesn't stringgrid support multiselect? (haven't used for so long I can't remember)

It does, but this doesn't mean it supports "select one only".

May I ask why you don't use stringgrid? Is there something better for GUIs?

2)to code a multi select ability you create a list of selected rows when the user checks the box you add the row to the list when the boxgets uncheckd you remove the row from the list. you do not keep the state of the selection in the grid / data you simple paint a checked box if the row is in the checked list, otherwise you paint an unchecked box. That is in my experience the less prone to errors method.

So basically the answer is: there is no automatic settings that handles this, do it by programming.

Thanks!
Title: Re: Stringgrid checkbox with select-only-one functionality
Post by: mijen67 on October 14, 2017, 07:59:27 pm
The OnCheckBoxToggled event is the best place to handle that. Then manually
select the items you want.

So basically the answer is: there is no automatic settings that handles this, do it by programming.

Thanks!
Title: Re: Stringgrid checkbox with select-only-one functionality
Post by: munair on October 16, 2017, 09:32:24 pm
The OnCheckBoxToggled event is the best place to handle that. Then manually
select the items you want.

So basically the answer is: there is no automatic settings that handles this, do it by programming.

Thanks!
How would you imagine this could be done automatically? The programmer must tell what happens when a user event occurs and code the appropriate event handler to make it happen. See it as a challenge to make it work just the way you imagine. Be creative! I promise you, it is fun and quite rewarding. Some programmers come up with ideas other would never have thought of. RAD already makes it very easy to quickly write great software. There must be something left for the programmer to do.  8)
TinyPortal © 2005-2018