Recent

Author Topic: StringGrid Clear? (solved!!!)  (Read 2046 times)

alpine

  • Hero Member
  • *****
  • Posts: 1303
Re: StringGrid Clear?
« Reply #15 on: March 12, 2023, 11:43:28 am »
its all about rows

I corrected the mistake since, but it still is complaining about col 0 being out od range.

I added then 3 rows instead of 1 , it works then, but first written rows staying empty.
You don't need to deal with columns once they are defined into the designer with a given Width, Title, etc.

I will test the last suggestions, but maybe should delete the control and redesign the Grid
with the object inspector all new. Not inserting titles, they will be written by code eacht time  a new line is added?
No need for that also. Fixed rows can stay as designed.
Just manage the number of rows by directly assigning to RowCount (don't forget to add the number of fixed rows) and then add an offset when accessing the Cells[col, row + fixed_rows]. That's all.
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

cdbc

  • Hero Member
  • *****
  • Posts: 1673
    • http://www.cdbc.dk
Re: StringGrid Clear?
« Reply #16 on: March 12, 2023, 02:08:29 pm »
Hi
@pentilisea:
I cooked up a little example for you, here it is.
The fixedrow property is set to 1 and fixedcol is set to 0...
Regards Benny
« Last Edit: March 12, 2023, 02:12:39 pm by cdbc »
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

pentilisea

  • Guest
Re: StringGrid Clear?
« Reply #17 on: March 12, 2023, 06:22:42 pm »
Well,
tried mucg but ends always with Index Out of range Cell[Col=1 Row=5]

If I previously add 5 rows then rows are written again but only after row 5 - if more rows are the empty rows raise...

Index Out of range Cell[Col=1 Row=5] is the current error

For the time I avoid this by deleting rows and adding empty rows and having  last row shown...

I'm going on with the other need stuff, maybe a solution turns up.

cdbc

  • Hero Member
  • *****
  • Posts: 1673
    • http://www.cdbc.dk
Re: StringGrid Clear?
« Reply #18 on: March 12, 2023, 06:43:43 pm »
Hi
Of course, if you reference Col = 1, you >Must< be sure, there are at least 2 columns present! The same, if you reference Row = 5, there has to be at least 6 rows, row 0 goes to the fixed row, so with rowcount = 6, you have 1..5 that are assignable... In my example, I add the rows as I need them and I control the colcount in the creation of the headers. In the populate... method I don't check anything, because I know... You oth have to check that your indexes are within range of the allocated grid "real-estate" or expand as you go.
Hth - Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

pentilisea

  • Guest
Re: StringGrid Clear?
« Reply #19 on: March 12, 2023, 07:51:05 pm »
Hi Benny,
thanks for your gridplay and comments.
I solved it by accident....

Code: Pascal  [Select][+][-]
  1.  for c:= spins downto 1 do
  2.  
  3.       StringGrid1.DeleteRow(1);
  4.  
  5.       StringGrid1.RowCount := StringGrid1.RowCount+spins;    

Sounds wiered, each time I add a row the variable spins is raised by 1.
Button47 has the code and pressed, does the job, but the problem with empty rows at start remains.
However, another procedure clears all variable and settings in order to load a new file into a listbox.
There I just added Button47.Click - and wonder, it does exacly what I wanted it to do in the first place.
When I write now new rows, it starts as wanted with row 1. Don't know why....
If I click button47 directly, empty rows remain.

So a long story, much time wasted, but I'm greatful for all your attention and help.
And before this becomes a never ending story, I mark this as SOLVED. (not really, but OK for now......
Klaus

 

TinyPortal © 2005-2018