Jump to content
Henry Olive

String Grid Header Title Caption Align

Recommended Posts

Good Day,

 

Delphi 11,3

I have a string grid (as a Data Grid) linked to datasource(Bind) 

In String Grid's Columns Editor, i choose one of the column (it is an Integer field)

i want   to change its Align and i set Aligment Property to taRightJustify 

when i run the application the column header.caption is still LeftJustify.

How can i change an Integer or Numeric fields's Align to taRightJustify ?

 

Thank you

 

 

Share this post


Link to post

I have looked for a way to adjust the caption titles as well and there doesn't seem to be a simple property like you'd expect. I suppose you could implement a custom draw event but I haven't needed to because I use Woll2Woll's FirePower grid for FMX and it does allow custom title alignments with a simple property.

Share this post


Link to post

Thank you so much, I'm new in FMX, beside StringGrid there is also Grid component i have just tried to use it but i think data connection is not possible can you please confirm. Thank you

Share this post


Link to post
1 hour ago, Henry Olive said:

i think data connection is not possible

Firemonkey doesn't have data-aware controls like the VCL does. Instead, you use LiveBindings which is more flexible and powerful but has a learning curve. 

 

I would suggest activating the LiveBindings Wizard to make hooking it up simpler: in Tools > Options > IDE > LiveBindings, check the box for "Display LiveBindings Wizard in context menu".

 

Then in your form, you can right+click on control (such as the grid) and select "LiveBindings Wizard" which will walk you through hooking it up.

Share this post


Link to post

In StringGrid, check the HeaderSettings.TextSettings.HorzAlign property for the desired column.

Share this post


Link to post
5 minutes ago, Kryvich said:

In StringGrid, check the HeaderSettings.TextSettings.HorzAlign property for the desired column.

There is no HeaderSettings directly off the StringGrid itself. However, it got me thinking...

 

This line of code works:

  StringGrid1.Columns[1].HeaderSettings.TextSettings.HorzAlign := TTextAlign.Trailing;

But, frustratingly, you cannot access the HeaderSettings of a Column at design-time.

Share this post


Link to post

In Design mode, select the desired column and in the Object Inspector panel you can view/change its properties.

  • Thanks 1

Share this post


Link to post
11 minutes ago, Kryvich said:

In Design mode, select the desired column and in the Object Inspector panel you can view/change its properties.

Yes, but the Header is only a simple string, it does not have a TextSetting sub-property. And the TextSettings property for the column in the object inspector only affects the data, not the header:

image.thumb.png.db280acc233259bbc9e6b4385f438903.png

 

Share this post


Link to post

Interesting. I've been playing around with a test project and it appears that when you apply LiveBindings to the grid, it hijacks the properties--and hides some of them. Your example is not using LiveBindings, mine was. As soon as I removed the table and LiveBindings components, then I could edit the column header TextSettings at design-time as you showed. I so seldom use StringGrid and then almost always use LiveBindings to hook up data sets, I had never encountered this before. Thanks for your screenshot.

  • Like 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×