Recent

Author Topic: [SOLVED]Inserting a column in an existing stringgrid  (Read 2126 times)

paul9531031

  • New Member
  • *
  • Posts: 13
[SOLVED]Inserting a column in an existing stringgrid
« on: March 27, 2020, 11:22:18 am »
I have a StringGrid with 6 columns, none of which are fixed.  Is it possible to insert a new fixed column on the left, i.e., in position 0?  If not with the IDE perhaps by amending the form code?
(When I tried adding a column it seemed only possible to put it on the right hand side.)
« Last Edit: April 01, 2020, 02:48:40 pm by paul9531031 »

Bart

  • Hero Member
  • *****
  • Posts: 5538
    • Bart en Mariska's Webstek
Re: Inserting a column in an existing stringgrid
« Reply #1 on: March 27, 2020, 11:32:09 am »
InsertColRow? (can't check right now, no Lazarus available ATM).

Bart

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Inserting a column in an existing stringgrid
« Reply #2 on: March 27, 2020, 11:37:40 am »
Another solution might be adding a column, moving all the data and (re)setting  FixedCols, which you can do relatively easyly either at run- or design-time.

But yes, InsertRowColumn() (and adjusting FixedCols) should do the trick
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Inserting a column in an existing stringgrid
« Reply #3 on: March 27, 2020, 11:45:39 am »
I have a StringGrid with 6 columns, none of which are fixed.
The answer depends slightly on whether you mean merely that
Code: Pascal  [Select][+][-]
  1. StringGrid1.ColCount = 6
or whether you mean
Code: Pascal  [Select][+][-]
  1. StringGrid1.Columns.Count = 6
since a grid with a non-nil StringGrid1.Columns is a somewhat different object from a string grid that lacks any Column items.

paul9531031

  • New Member
  • *
  • Posts: 13
Re: Inserting a column in an existing stringgrid
« Reply #4 on: March 27, 2020, 11:58:13 am »
For clarity, I definitely want to insert the new column at design time, not run-time.

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Inserting a column in an existing stringgrid
« Reply #5 on: March 27, 2020, 12:18:23 pm »
For clarity, I definitely want to insert the new column at design time, not run-time.

Then it shouldn't be difficult: add the column as you did the others and set FixedCols or use the Grid Editor to move the column to the left (right-click on the grid and select "Edit StringGrid..."). See attached image.

Or you can use the columns editor (in the Object Inspector, double-click "Columns" or clikc its "...") button: add the column and move it up to the top.
« Last Edit: March 27, 2020, 12:21:34 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

 

TinyPortal © 2005-2018