Topic: TableGrid Header Style and format

Hi,

I would like to format the header of my tablegrid, but seems I cannot find an answer.

what is odd, is that the following are working:

         frmSearch.edTableGrid1.Columns[0].Font.Style := fsBold;
          frmSearch.edTableGrid1.Columns[0].Header.Alignment := taCenter;
          frmSearch.edTableGrid1.Columns[1].Header.Alignment := taCenter;
          frmSearch.edTableGrid1.Columns[2].Header.Alignment := taCenter;
          frmSearch.edTableGrid1.Columns[0].Footer.Color := clYellow; //this is for the footer text color
          frmSearch.edTableGrid1.Columns[0].Footer.Alignment := taCenter;

which include also the Header alignment.

But these:

         frmSearch.edTableGrid1.Columns[0].Header.Color := $0066FF66; //this is for the header text color
         frmSearch.edTableGrid1.Columns[1].Header.Color := clRed;
         frmSearch.edTableGrid1.Columns[2].Header.Color := clMoneyGreen;

are totally ignored. No errors compiling, just no change in my table header.

Am I too stupid or I am missing something?

version 4.1 used

thank you for your help !!!

2 (edited by derek 2017-12-28 17:44:30)

Re: TableGrid Header Style and format

Hi 01xbruno,
The syntax of what you are trying to do looks fine.  What event are you associating with altering the colours for the column headers?
In the attached example, I'm using the form1_tablegrid1_onchange event, and it seems to be working as you want.
Regards,
Derek.

Post's attachments

Attachment icon ox1bruno.zip 338.16 kb, 498 downloads since 2017-12-28 

Re: TableGrid Header Style and format

Hello 01xbruno, Hello Derek

I met same problem with an old version of MVD.
So to fix it, I added this statement :

Form1.GridEmployees.EnableVisualStyles := False;

between the final duo BEGIN  ... END. (with a dot) at the end of script.

But now with MVD 4.x, there is a property for Grid called EnableVisualStyle (behind the group Aditionnal).
If you check  it, you would not meet any problem.

Is it OK for you ?

Best regards

JB

Re: TableGrid Header Style and format

Thanks Derek,

Thank you for the help but your sample does not have any color in the header of the table.

All I see is a green cell in the footer where there is the total of the entries.
i see your script, and like mine, does nothing as far changing color on the header.

I will try the other option now from Jean....

Thanks again

Bruno

Re: TableGrid Header Style and format

Thanks Jean,

I tried both your solutions, but no luck.

I am attaching a picture to show what I mean.

For your info, I have also changed the HeaderStyle in the Object inspector to ALL options but no difference.

Post's attachments

Attachment icon Example1.jpg 38.38 kb, 308 downloads since 2017-12-28 

Re: TableGrid Header Style and format

Just for info, here is my script section:

procedure frmSearch_edTableGrid1_OnChange (Sender: String);
begin

          frmSearch.edTableGrid1.Columns[0].Font.Style := fsBold;
        frmSearch.edTableGrid1.Columns[2].Header.Color := $0066FF66; //this is for the header text color
        frmSearch.edTableGrid1.Columns[1].Header.Color := clRed;
        frmSearch.edTableGrid1.Columns[0].Header.Color := clMoneyGreen;
          frmSearch.edTableGrid1.Columns[0].Header.Alignment := taCenter;
          frmSearch.edTableGrid1.Columns[1].Header.Alignment := taCenter;
          frmSearch.edTableGrid1.Columns[2].Header.Alignment := taCenter;
          frmSearch.edTableGrid1.Columns[0].Footer.Color := clLime; //this is for the footer text color
          frmSearch.edTableGrid1.Columns[0].Footer.Alignment := taCenter;
          frmSearch.edTableGrid1.Columns[2].Options :=frmSearch.edTableGrid1.Columns[2].Options - coShowTextFitHint; // for third column

end;

procedure frmDataEntry_edLink_OnDoubleClick (Sender: TObject);
begin

end;


begin
     frmSearch.mniFile.Visible := False;
     frmSearch.mniOptions.Visible := False;
     frmSearch.mniAbout.Visible := False;
     frmSearch.edTableGrid1.EnableVisualStyles := False;

end.


I have attached the test file for your perusal.

Thanks

Bruno

Post's attachments

Attachment icon 01XPC.zip 8.91 kb, 451 downloads since 2017-12-28 

Re: TableGrid Header Style and format

Hi Bruno,
Looks (at least from my end) that the problem lies with the headerstyle object property for the grid. 
If you choose 'hsauto' as the headerstyle (which is the default) then the header colouring works (see the .jpg screen capture in the attachment).  Switch it to some of the other options (hsoffice2010 for example) and you lose the colouring. 
One for Dmitry to have a look at, I suspect.
Attached is your example with the tablegrid headerstyle property set to 'hsauto' which should show your colours.
Out of interest, In the example I sent earlier, the tablegrid headerstyle was already set to 'hsauto' - did that not show up with coloured headers or did  you change the headerstyle property?
Derek.

Post's attachments

Attachment icon bruno.zip 421.72 kb, 493 downloads since 2017-12-28 

Re: TableGrid Header Style and format

Thank you Derek,

the HeaderStyle set to anything else than hsAuto stopped the formatting.

The sample you sent me was not changed, I include picture of it with the hsAuto on. The header is not colored, perhaps the suggestion of Jean:

frmSearch.edTableGrid1.EnableVisualStyles := False;

did the trick...

I will try it.

thanks again for the help and let's hope Dmitry will find about the other options ( hsOffice2007 etc) why they do not allow for formatting...

Bruno

Post's attachments

Attachment icon Example2.jpg 82.12 kb, 265 downloads since 2017-12-28 

Re: TableGrid Header Style and format

Derek, Jean

Indeed the combination of the 2 solutions are the SOLUTION.

See the Derek sample after adding the Form1.GridEmployees.EnableVisualStyles := False;

So the solution is:

1) Add to the final Begin Form1.GridEmployees.EnableVisualStyles := False; end.
2) tablegrid headerstyle property set to 'hsauto'

Great. I hope will help others too.

Thank you guys....

Post's attachments

Attachment icon Example3.jpg 74.69 kb, 244 downloads since 2017-12-28