Forum > LCL

Radiobox "Owner Drawn"

<< < (2/3) > >>

Thank you for all answers.
Yes, I want the function of selecting ONE radiobutton.
About Arioch's answer.
I tried it, but am not very excited about the result:
The problem is, that my groups are not of the same size.
I grouped the radiobox in columns and there I want e.g. the first column five items, the second three and the fifth four.
The items shall belong to my headers.
Or did I do something wrong?

I wonder, if I shall work with 6 radiogroups and let them interact in the way, that each selection makes the 5 others to set their itemndex to -1.
Does this sound, as it would work?
But how to grab the results? I would have to digg into the mess of 5 groups.


--- Quote from: Nicole on September 27, 2022, 12:32:40 pm ---I wonder, if I shall work with 6 radiogroups and let them interact in the way
But how to grab the results? I would have to digg into the mess of 5 groups.

--- End quote ---

You make the form-level private property and encapsulate all that mess inside one getter and one setter functions.
You also make a single OnClick event for all the radiogroups. But notice, that the name is wrong, the event is actually on-change one, so when RG 1 would be removing selection from RG 2 - that group 2 would fire it immediately, reentrantly. See recent forum threads on TCheckBox for the evermore batle of "be Delphi-compatible" vs "be consistent"

However, you have to think in advance about "composite item index" - how would you identify those items? What this propery would reort/accept as a value?
Would you just make incremental values, then, for example, you had 3 radiobuttons in group 1, then you want to add a 4th radiobutton there, but you can not. This RB then would be #3 but all your code and databases already fixed it that #3 is the first radiobutton of the seconf group...

OTOH, that holds for every visual design, radiogroups or not.

And from visual design point i dislike the radiogroups, as they might confuse user... Hopefully not for long, but still.

Maybe you can go with TListBox or with TComboBox/TComboBoxEx instead. Albeit i personally think the "selected" state in fancy modern combobox is much less visually distinct than "dull old" radiobutton.

--- Quote from: Nicole on September 27, 2022, 12:32:40 pm ---The problem is, that my groups are not of the same size.

--- End quote ---

Are they really so large, than multi-column layout is required?  Today many screens are large. Okay, the cheapest laptops seem to stick as 1300x760, yet even that is actually a lot.  Funny to remember, many years ago i believed 1024x768 was the ideal resolution and increasing it further would be worsening human experience.

You never hinted at that before, BTW.

Some problem with multi-column is that you can no more have easy auto-size. You would have to fix the size of all the controls in designtime, and then hope the scaling for different font sizes and display resolutions would happen automagically. Hopefully it would.

But okay then, try your luck with TFlowPanel. But then all the "hader labels" and all the radiobuttons would have to have no Align and no AutoSize but carefully selected sizes.
Also you would probably want to use TFlowPanel.OnResize to proactively make header labels almost as wide (save few pixels for margins and borders) as TFlowPanel.CustomWidth
Or maybe headerlabels ".Anchors" could do it automagically, but i was hit few times with inconsistent Anchors in Delphi under less than trivial conditions, like those with lockdowns and remote work, so today i abhor Anchors.

Additionally, what if a user resizes the window (and the panel) and your 4-columns design suddenly snaps into 3-columns design? You would, perhaps, have to use TFlowPanel.OnResize to smartly resize radiobuttons, so they retain the order once designed.

You can also try with TGridPanel but i am not sure it would be a good choice here, both "headerlables" that have to span several columns (all of them, actually) and then all columns having the same width, meaning a really long RB in group2 col2 would make equally wide slot for otherwise narrow RB in group1 col1


--- Quote from: Nicole on September 26, 2022, 07:18:25 pm ---Any ideas?
--- End quote ---

Please show a picture of your doing since after re-reading it makes not that much sense with splitted radiobuttons under different headers but just one of all shall be selected.
I mean, in my experience a header opens a new territory for a selection to be set, bound to headers title. I have no example in my head that opens something the way you want it to be done.

What about "faking" Radiogroups?
See my example program

I extended my example.
See screenshot and project-sourcecode


[0] Message Index

[#] Next page

[*] Previous page

Go to full version