1 (edited by AD1408 2024-05-03 15:36:20)

Topic: Combo bgColor...

Hi All,
I wanted to change combobox bgColor and font color with following script but it didn't work.
Any correction please?

if (Form1.cbItemRating.Text = '09') and (Form1.cbItemRating.Text = '10') then Form1.cbItemRating.Color := clRed else Form1.cbItemRating.Color := $00604046;
if (Form1.cbItemRating.Text = '09') and (Form1.cbItemRating.Text = '10') then Form1.cbItemRating.Font.Color := clWhite else Form1.cbItemRating.Font.Color := clYellow;

I put the script under form1 onShow, tablegrid cell click and combobox onChange.
Combobox contains  1 to 10 as text db field.

Adam
God... please help me become the person my dog thinks I am.

Re: Combo bgColor...

Hi Adam,
I think your condition should be 'or' rather than 'and' (it can't be both '09' and '10' at the same time).
Or if your numbers (or letters) are contiguous, you can check for them being in a range which makes the script a bit more concise (see attached).
Derek.

Post's attachments

Attachment icon adam value in ranges.zip 350.48 kb, 64 downloads since 2024-05-03 

Re: Combo bgColor...

Hi Derek,
Thank you very much....
Your kind help truly appreciated........

Since giving up smoking my logic focus functions are suffering a bit.
Thanks again for the sample project and showing new ways of doing things.

Adam
God... please help me become the person my dog thinks I am.

4 (edited by AD1408 2024-05-03 23:10:38)

Re: Combo bgColor...

Hi again Derek,
It's all fine working fine until I use double digit numbers.


This works fine:

if (form1.combobox1.text in ['8'..'9']) then form1.combobox1.Color := clred else form1.combobox1.color := clwhite;
if (form1.combobox1.text in ['8'..'9']) then form1.combobox1.Font.Color := clyellow else form1.combobox1.font.color := clblack;

But this doesn't:

if (form1.combobox1.text in ['9'..'10']) then form1.combobox1.Color := clred else form1.combobox1.color := clwhite;
if (form1.combobox1.text in ['9'..'10']) then form1.combobox1.Font.Color := clyellow else form1.combobox1.font.color := clblack;

Here is the way I'm doing it:

Post's attachments

Attachment icon cbColoring.zip 5.83 kb, 42 downloads since 2024-05-04 

Adam
God... please help me become the person my dog thinks I am.

Re: Combo bgColor...

Hi Adam,
As you've noticed, it's when you have a range that includes single and double digits (or double and triple digits etc etc).
Probably the easiest way around it is to use combinations of range values and, if relevant, single values.  For example, in the attached example, there are range values of 8-9 and 15-17 and single values of 4, 10 and 12.
But in terms of writing the script,  it's still less verbose that having to write discrete 'where' clauses for each individual value.

Post's attachments

Attachment icon cbColoring.zip 338.3 kb, 34 downloads since 2024-05-04 

Re: Combo bgColor...

Thanks a lot Derek.....
Now, all good and working.

Adam
God... please help me become the person my dog thinks I am.

7 (edited by AD1408 2024-05-05 14:13:35)

Re: Combo bgColor...

With the combo bg and text coloring script I get selection color highlight of combo text - see image below. Is there a way to stop the highlight.


https://thumbs2.imgbox.com/4b/69/mInZ9y8P_t.jpg

Post's attachments

Attachment icon cbColSel01.jpg 2.75 kb, 6 downloads since 2024-05-05 

Adam
God... please help me become the person my dog thinks I am.

Re: Combo bgColor...

Hi Adam,
I've always found it to be a case of 'either / or' - you can change the text color of the combobox but then it also highlights the selected row or you can just change the background color (and leave the text color as is) and it doesn't highlight the selected row (see attached).
If you go with that as a fix (well, a compromise at best!!), then perhaps chose a different background color that doesn't obscure the value in the highlighted row quite so much.
I also had a quick play with changing the font to 'bold' but that seemed to skew other things and ended up worse than the problem it was trying to solve!  sad
Derek.

Post's attachments

Attachment icon cbColoring.zip 338.04 kb, 33 downloads since 2024-05-05 

9 (edited by sparrow 2024-05-05 17:40:43)

Re: Combo bgColor...

Hi Adam, Derek

Adam, You can create a component (for example Edit) place it behind another element or move it outside the boundaries of the form.
Switch focus to Edit after selecting in the combobox.

Post's attachments

Attachment icon cbColoring.zip 292.06 kb, 44 downloads since 2024-05-05 

Re: Combo bgColor...

Hi Derek,
Hi Sparrow,


Thanks a lot guys.........
Nice lil trick Sparrow... I'm sure it would benefit many MVD users here.

Adam
God... please help me become the person my dog thinks I am.