[SOLVED] How do I set the StringGrid column title at run time? lazarus / 31-LCL ---------------------------------------------------------------------- Hopestation · 2018-02-10 21:22 Hi. I have tried using StringGrid.Cells[1,0] := 'ABC'; This was accepted during compilation but ignored at run time. I changed it to StringGrid.Cells[1,1] := 'ABC'; and it changed the text in the first row Then I found TGridColumnTitle. I tried StrGrd.Columns.Items[1].Title := 'ABC'; This was rejected because 'ABC' isn't a TGridColumnTitle. I tried declaring VAR   aTitle: TGridColumnTitle; Then I set aTitle := 'ABC' I got  Error: Incompatible types: got "Constant String" expected "TGridColumnTitle" How do I set a Column title? ---------------------------------------------------------------------- Blaazen · 2018-02-10 21:33 TryCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i StrGrd.Columns.Items[1].Title.Caption := 'ABC'; ---------------------------------------------------------------------- Hopestation · 2018-02-11 09:58 Thanks for your help, I am still mystified as to why setting the cell values didn't work. Trying to read from row 0 doesn't work either. I tried it after reading Taazz's reply to a similar question in 2013: https://forum.lazarus.freepascal.org/index.php?topic=21164.0 You also answered that query and didn't disagree with him. Has the StringGrid changed since then? ---------------------------------------------------------------------- Hopestation · 2018-02-11 11:37 After writing to the column title caption I went on to try to set its font size. Following the above format I went through the procedure of adding a property followed by a dot and waited for the box of options to appear. I got StrGrd.Columns.Items[N].Title.Font.Size:= 9; This doesn't work, so I tried   StrGrd.Columns.Items[N].Title.Font.Caption. and got a long list of options, but size wasn't included. What is going wrong? ---------------------------------------------------------------------- bigeno · 2018-02-11 11:41 AFAIK if you use custom columns then column title will override the values specified in cells[x,0] ---------------------------------------------------------------------- bigeno · 2018-02-11 11:45 And I always use StrGrd.Columns[N].Title.Font.Size:= 9; instead of StrGrd.Columns.Items[N].Title.Font.Size:= 9; ---------------------------------------------------------------------- wp · 2018-02-11 12:03 If you want to do something at runtime but don't know how things are named you're out of luck. Before you begin at runtime do the same at designtime, then you see all the names and their relation in the ObjectInspector: Add a stringgrid to the form. Add some columns (Click at '...' next to "Columns", click "+ Add") Select a column in the component tree above the property list in the object inspector. In the property list find the node "Title", open it. It has a "Font", open it. Find the "Size" and change the value. In total you have this:   - StringGrid1   - Columns[index]  ("index" is the index of the column which you clicked, it is listed in the componenttree)   - Title   - Font   - Size Write all these names separated by a '.' - and you got it! Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  StringGrid1.Columns[index].Title.Font.Size := something; ---------------------------------------------------------------------- Bart · 2018-02-11 13:08 Quote from: wp on February 11, 2018, 01:03:56 pmIf you want to do something at runtime but don't know how things are named you're out of luck. Not quite, if you can guess a little bit what you're after then  use the Lazarus CodeTools to help you: type StringGrid1. waite a while, select Columns from dropdownlist, type [index] and another period (.) wait for next dropdownlist, select Title, type another period etc. Bart ---------------------------------------------------------------------- wp · 2018-02-11 13:23 Quote from: Bart on February 11, 2018, 02:08:19 pmQuote from: wp on February 11, 2018, 01:03:56 pmIf you want to do something at runtime but don't know how things are named you're out of luck. Not quite, if you can guess a little bit what you're after then  use the Lazarus CodeTools to help you: type StringGrid1. waite a while, select Columns from dropdownlist, type [index] and another period (.) wait for next dropdownlist, select Title, type another period etc. Bart Yes. That's another way. Or use the source code: CTRL-Click on TStringGrid in the interface of the mainform, and the editor will open the file in which TStringGrid is implemented, and you see all properties and methods of it. You may want to CTRL-Click again on properties or their type to get to their implementation/declaration. ---------------------------------------------------------------------- jamie · 2018-02-11 14:10 Ha, that's a neat trick in deed! Thanks... that saves a lot of time.. One of these days I need to take a shot at putting in a PRINT function for the Short Cut keys so I can have a quick reference to them.. Thanks ---------------------------------------------------------------------- Hopestation · 2018-02-11 17:29 Thanks for all your answers. They've helped a lot. Is there an answer why StringGrid.Cells[1,0] := 'ABC'; doesn't work? According to Taazz it should. ---------------------------------------------------------------------- jamie · 2018-02-11 17:42 if you have implemented COLUMNS.Count > 0 then the header gets overridden. More than likely when you make an attempt to change that, it just gets over written on the next repaint.  have you read back what you put there ? If it comes back as to what you put there and you don't see it appearing on the cell, that verifies the case, cell is getting over painted via the COLUMNS.TGridColmn..  You can change the contents of the columns[1].Title.Caption :'ABC'; I think that will work or its close to it. ---------------------------------------------------------------------- Hopestation · 2018-02-13 11:01 I set the number of columns at design time. It doesn't change at run time. Thanks for your help.