Recent

Author Topic: [SOLVED] How can i change width of StringGrid ?  (Read 2994 times)

majid.ebru

  • Sr. Member
  • ****
  • Posts: 494
[SOLVED] How can i change width of StringGrid ?
« on: March 18, 2018, 09:59:17 am »
Hi

i have a stringGrid :
Code: Pascal  [Select][+][-]
  1. StG_P8_2.ColCount := 103;
  2. .
  3. .
  4. StG_P8_2.columns := 0;
  5. .
  6. .
  7. StG_P8_2.Options:= StG_P8_2.Options + [goEditing];
  8. .
  9. .
  10. StG_P8_2.Options:= StG_P8_2.Options + [goColSizing];
  11.  

when i use this code :

Code: Pascal  [Select][+][-]
  1. StG_P8_2.Columns[1].Width:= 10;

i see Error ?
« Last Edit: March 21, 2018, 12:31:13 am by majid.ebru »

ASerge

  • Hero Member
  • *****
  • Posts: 2223
Re: How can i change width of StringGrid ?
« Reply #1 on: March 18, 2018, 10:24:49 am »
Code: Pascal  [Select][+][-]
  1. StG_P8_2.columns := 0;
  2.  
It does not even compile. Can we see the working code, not the imaginary?

Handoko

  • Hero Member
  • *****
  • Posts: 5132
  • My goal: build my own game engine using Lazarus
Re: How can i change width of StringGrid ?
« Reply #2 on: March 18, 2018, 10:26:52 am »
On my tests, I got exception if I use this:
StG_P8_2.ColCount := 103;

Try this below, it works:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3.   StringGrid1.Columns.Clear;
  4.   StringGrid1.Columns.Add;
  5.   StringGrid1.Columns.Add;
  6.   StringGrid1.Columns.Add;
  7.   StringGrid1.Columns[0].Title.Caption := 'No';
  8.   StringGrid1.Columns[0].Width := 40;
  9.   StringGrid1.Columns[1].Title.Caption := 'Name';
  10.   StringGrid1.Columns[1].Width := 80;
  11.   StringGrid1.Columns[2].Title.Caption := 'Price';
  12.   StringGrid1.Columns[2].Width := 60;
  13. end;

majid.ebru

  • Sr. Member
  • ****
  • Posts: 494
Re: How can i change width of StringGrid ?
« Reply #3 on: March 18, 2018, 10:57:02 am »
Code: Pascal  [Select][+][-]
  1. StG_P8_2.columns := 0;
  2.  
It does not even compile. Can we see the working code, not the imaginary?

i know , i just want to show it

majid.ebru

  • Sr. Member
  • ****
  • Posts: 494
Re: How can i change width of StringGrid ?
« Reply #4 on: March 18, 2018, 11:01:27 am »
On my tests, I got exception if I use this:
StG_P8_2.ColCount := 103;


in my program ,this code , works.
Code: Pascal  [Select][+][-]
  1. StG_P8_2.ColCount := 103;

i don't use your code :
Code: Pascal  [Select][+][-]
  1. StringGrid1.Columns.Add;
  2.  

and i use this code :
Code: Pascal  [Select][+][-]
  1. StG_P8_2.InsertRowWithValues(StG_P8_2.RowCount,FlashingArray);
  2.  

but i try your codes

Handoko

  • Hero Member
  • *****
  • Posts: 5132
  • My goal: build my own game engine using Lazarus
Re: How can i change width of StringGrid ?
« Reply #5 on: March 18, 2018, 11:17:51 am »
On my tests, I got exception if I use this:
StG_P8_2.ColCount := 103;

in my program ,this code , works.
Code: Pascal  [Select][+][-]
  1. StG_P8_2.ColCount := 103;

You didn't get exception because you had not provide any columns for the StringGrid at design time. I got error because I already provided some columns at design time.

Handoko

  • Hero Member
  • *****
  • Posts: 5132
  • My goal: build my own game engine using Lazarus
Re: How can i change width of StringGrid ?
« Reply #6 on: March 18, 2018, 11:21:12 am »
i don't use your code :
Code: Pascal  [Select][+][-]
  1. StringGrid1.Columns.Add;
  2.  

and i use this code :
Code: Pascal  [Select][+][-]
  1. StG_P8_2.InsertRowWithValues(StG_P8_2.RowCount,FlashingArray);
  2.  

Then that might be the problem. We're talking about column, but what you're doing is adding rows.

majid.ebru

  • Sr. Member
  • ****
  • Posts: 494
Re: How can i change width of StringGrid ?
« Reply #7 on: March 18, 2018, 11:44:55 am »
yes sorry

i don't change number of colunms.

at first , i set colcount to 103.

then i just add rows.

i don't add colunms in runtime.

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: How can i change width of StringGrid ?
« Reply #8 on: March 18, 2018, 12:03:56 pm »
Hi

i have a stringGrid :
Code: Pascal  [Select][+][-]
  1. StG_P8_2.ColCount := 103;
  2. .
  3. .
  4. StG_P8_2.columns := 0;
  5. .
  6. .
  7. StG_P8_2.Options:= StG_P8_2.Options + [goEditing];
  8. .
  9. .
  10. StG_P8_2.Options:= StG_P8_2.Options + [goColSizing];
  11.  

when i use this code :

Code: Pascal  [Select][+][-]
  1. StG_P8_2.Columns[1].Width:= 10;

i see Error ?
string grid in lcl has 2 different mechanisms to define and use columns
1) Col, ColCount, ColWidth. delphi compatible
2) the columns property more OO.

Someone made the unfortunate decision to have them separated you can use one or the other but not both.

here is a working sample on how to set the column width in your case.
Code: Pascal  [Select][+][-]
  1.   StringGrid1.ColCount := 103;
  2.   StringGrid1.ColWidths[0] := 8;
  3.   StringGrid1.ColWidths[1] := 50;
  4.   StringGrid1.ColWidths[2] := 70;
  5.   StringGrid1.ColWidths[3] := 130;
  6.   StringGrid1.ColWidths[4] := 110;
  7.   StringGrid1.ColWidths[5] := 90;
  8.  
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

majid.ebru

  • Sr. Member
  • ****
  • Posts: 494
Re: How can i change width of StringGrid ?
« Reply #9 on: March 18, 2018, 12:09:02 pm »
@ taazz Thank you very much :-* :-* :-* :-*

it worked.

 

TinyPortal © 2005-2018