Topic: Changing colors in a table grid

Hi All,
I would like to have a field and text in a tablegrid change color when the field contains a certain word (Overdue).  I have the following code and it works fine. Note this code came from an earlier post from Derek(thanks Derek):
procedure frmMainMenu_tblGridInstalled_OnChange (Sender: TObject);
var
   i,c: integer;
begin
  c := frmMainMenu.tblGridInstalled.RowCount -1;
  for i := 0 to c do
  begin
    if frmMainMenu.tblGridInstalled.Cells[4,i] = 'Overdue' then
      begin
        frmMainMenu.tblGridInstalled.Cell[4,i].Color := clRed;
        frmMainMenu.tblGridInstalled.Cell[4,i].TextColor := clWhite;
      end;
   end;
end;

.
My problem is when I go back into the table grid at a later time, and I highlight one of the rows that has the Red/White text, it changes to Black. 
.
Then when I move to another row, this row changes to Black and the previous row I had selected goes back to Red/White.  I've been trying to find out why this happens and haven't found an answer so far.
.
Any thoughts will be appreciated.
Thanks, Frank

Re: Changing colors in a table grid

Hello Frank.
It happens when you highlight a row - the default highlight colours for the cell background and the cell text take precedence over whatever colours you might have set.
The simplest way might be to untick the 'selectfullrow' option in the tablegrid properties so that only the first cell in the row is highlighted (but it's not ideal).
Derek.

Post's attachments

Attachment icon gridlines.zip 337.17 kb, 213 downloads since 2021-11-15 

Re: Changing colors in a table grid

Derek,
It looks like this fix will work for me. By unchecking the 'selectfullrow" option my colors don't change which is great.
And now when I click on a field in the table it highlights only that field and doesn't change the others.
.
Also if a user wants to change the info in one of the fields for a record they can double-click on it and go to that record.  Since the whole row is not highlighted they'll just have to learn that by double-clicking any field in the row it will take them to the full record.  As you mentioned, not perfect, but for me it looks like it's doable.
.
My only complaint is that it took me a while to find where to uncheck that option.  I do have to complain about something LOL.  MVD has so darn many property options that I'll probably never learn them all.  And half of them I have no idea what they are for??
.
Many thanks, I should have asked before I spent so much time trying to figure it out myself.  But on the plus side I get a lot of practice and hopefully learn more stuff.
.
See, I'm not too old to learn new stuff.  Hint - but I am old !  If anyone guesses how old I am I'll buy them a beer.  Sorry sometimes I get a little carried away smile
.
Many thanks to yourself and all the great folks on the forum.
Frank

Re: Changing colors in a table grid

Hello Derek & Frank,
Thanks for the above discussion. I want to know two things,
(!) how the Edit button in Form 1 works? There is no procedure Form1_TableGrid1_OnClick in the script, and
(2) in general, how, and when to use the table grid property option @goMultiselect@?
Regards,
Eyeman

Re: Changing colors in a table grid

Hi Eyeman,
1. 
It's 'standard' MVD functionality so does not need a discrete procedure. 
When you edit a record in MVD, you can either highlight the row in the tablegrid and then click the button that has been defined as 'showrecord' OR you can simply double-click the required row in the tablegrid. 
This holds true irrespective of whether you have the 'showrecord' button visible or invisible (just because it's invisible, doesn't mean that you can't still double-click on the required row).
I usually make the 'showrecord' button invisible to have the form as 'clean' as possible and also because it's easier and quicker for the user to double-click on a row rather than single-click and then move to the bottom of the screen to single click on the 'showrecord' button (I've never actually seen any user do it that way).
2.  The tablegrid option (gomultiselect) is used in conjunction with reporting. 
Rather than print ALL records in the tablegrid or just ONE record, gomultiselect enables you to select and print whatever records from the tablegrid you want. 
These records may be contiguous (in which case, select the first record you want, then hold down the 'shift' key and then select the last record you want (in the attached example, you might select item 03 through to item 07). 
Or you might want to select random items (select the first record you want, then hold down the CTRL key and select any number of additional items from anywhere in the tablegrid - for example, select item 08, item 03, item 05 in the attached example). 
Then when you click on the 'report' button, only the selected records will be printed.
Derek.

Post's attachments

Attachment icon gridlines2.zip 337.61 kb, 208 downloads since 2021-11-16 

Re: Changing colors in a table grid

Hello Derek,
Thanks a lot. Now I have a better understanding.
The "Edit" button has to be in the form if the tablegrid data is to be edited. Double-clicking the selected row in the tablegrid will activate the "Edit" button, whether it is visible or not. If it is made visible, then one may single-click a row to select it and then click the "Edit" button to modify data. Definitely, making the button invisible makes a form cleaner, since it functions as intended as double-clicking a row is usual user behaviour.
I also learn the use of the goMultiselect option for creating a precise report.
Thanks again for your guidance and teaching.
Regards,
Eyeman