2

i have this problem:

I needed to hide a row in a string grid so i simply did something like:

StringGrid.RowHeights[StringGrid.Row] := 0;

So this basicly sets the row height to 0 and it looks hidden. But after i do this and if i try to scroll i got a "Grid index out of range". If i click on another cell the error doesn't show up after i scroll. So it only shows when i hide it and then scroll directly after hiding a row.

Why does this happen and how can i fix it please?

user5014677
  • 694
  • 6
  • 22

2 Answers2

0

You are not quite supposed to do that. Instead of making the heights 0 you can simply 'skip' putting the data in the rows you want to hide.

For example, your table is like this:
a b c
d e f
and you want to hide the second row, then you say: RowCount:= RowCount-1 and simply don't display the data in that row.
For this you need a procedure (let's call it RefreshData) which will show the data in the grid, will decide which data rows to show or not and will calculate how many rows the grid should have.

Gabriel
  • 20,797
  • 27
  • 159
  • 293
0

I had a problem where I'd get the grid index out of range error when attempting to modify colcount or rowcount on a stringgrid. I debugged the grid.pas and figured out the error was because I was accidentally setting the ColWidth property of the negative first column to -1 like ColWidth[-1] = -1. That had the effect of modifying some memory of an array that stores the list of widths of each column and the control would act as if the columns and rows did not exist when attempting to add more. Only putting this here because I searched all over the internet to find the answer and there was nothing so maybe someone else will make the same mistake.

  • 1
    Please format your answer. Give spaces, indentation, make bold or italic where necessary. Check this link https://stackoverflow.com/editing-help – Muhammad Tariq Apr 01 '21 at 05:06