Recent

Author Topic: TStringGrid Title.Caption  (Read 13827 times)

totya

  • Hero Member
  • *****
  • Posts: 722
TStringGrid Title.Caption
« on: January 22, 2011, 11:52:30 am »
Hi!

I put TStringGrid to the new form.

Code: [Select]
procedure TForm1.Button1Click(Sender: TObject);
var i:integer;
begin
  for i:=1 to 2 do StringGrid1.Columns[i].Title.Caption:=IntToStr(i);
end;

This code cause error: "EListError, list index(1) out of bounds.
But why? Default Colcount is 5.

My version is: Lazarus-0.9.31-29128-fpc-2.4.3-20110120-win32.exe

Thanks!

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1933
Re: TStringGrid Title.Caption
« Reply #1 on: January 22, 2011, 11:56:16 am »
ColCount <> Columns

Add some Columns first

totya

  • Hero Member
  • *****
  • Posts: 722
Re: TStringGrid Title.Caption
« Reply #2 on: January 22, 2011, 12:02:13 pm »
ColCount <> Columns

Add some Columns first

Hi thanks, but Help wrote:
Quote
protected property TCustomGrid.ColCount: Integer
This is the number of columns in the grid, including fixed and normal columns.

Why I need add columns, if these already in StringGrid?

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1933
Re: TStringGrid Title.Caption
« Reply #3 on: January 22, 2011, 12:42:46 pm »
Why I need add columns, if these already in StringGrid?

They don't have the same meaning. ColCount column-properties are not accessible individually, as your error says.
It's not ideal. See also:
http://bugs.freepascal.org/view.php?id=12823

Scoops

  • Full Member
  • ***
  • Posts: 104
Re: TStringGrid Title.Caption
« Reply #4 on: January 22, 2011, 01:50:56 pm »
Hi,

If you want to write integer to the stringgrid try writing to the cells:

Code: [Select]
procedure TForm1.Button1Click(Sender: TObject);
var i:integer;
begin
  for i := 1 to 2 do stringgrid1.cells [i,0] := inttostr (i);
end;

hope it helps

« Last Edit: January 22, 2011, 02:01:45 pm by Scoops »

totya

  • Hero Member
  • *****
  • Posts: 722
Re: TStringGrid Title.Caption
« Reply #5 on: January 22, 2011, 02:09:19 pm »
Hi,If you want to write integer to the stringgrid try writing to the cells:...........

Hi, thx, but I know this :)

And, this is can't works, if uses Columns. Columns need of PickList, etc...
« Last Edit: January 22, 2011, 03:45:36 pm by totya »

asdf

  • Sr. Member
  • ****
  • Posts: 310
Re: TStringGrid Title.Caption
« Reply #6 on: February 02, 2011, 07:48:55 am »

// try this first and compile
procedure TForm1.Button1Click(Sender: TObject);
var i:integer;
begin
  for i:=1 to 1 do   // try this first and change to  i:=1 to 2...., you'll understand the wonder of grid.
  begin
  StringGrid1.Columns.Add; // Add 1 column
  StringGrid1.Columns[i-1].Title.Caption:=IntToStr(i);
  end;
end;
Lazarus 1.2.4 / Win 32 / THAILAND

mdalacu

  • Full Member
  • ***
  • Posts: 234
    • dmSimpleApps
Re: TStringGrid Title.Caption
« Reply #7 on: January 10, 2014, 02:45:23 pm »
Hi, can i reference a column by it's title name? like filedbyname?
Ex:
Code: [Select]
StringGrid1.ColumnByName('ColumnA').Rows[i]:='SampleText1';Is it posibble? Thank you.
« Last Edit: January 13, 2014, 09:53:15 am by mdalacu »

 

TinyPortal © 2005-2018