Forum > Beginners

StringGrid Clear? (solved!!!)

<< < (4/4)


--- Quote from: pentilisea on March 12, 2023, 11:33:21 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.

--- End quote ---
You don't need to deal with columns once they are defined into the designer with a given Width, Title, etc.

--- Quote from: pentilisea on March 12, 2023, 11:33:21 am ---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?

--- End quote ---
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 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

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.

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

Hi Benny,
thanks for your gridplay and comments.
I solved it by accident....

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- for c:= spins downto 1 do       StringGrid1.DeleteRow(1);       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......


[0] Message Index

[*] Previous page

Go to full version