Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TStringGrid FixedRows problem

Status
Not open for further replies.

aprobe

Programmer
Dec 4, 2003
36
NZ
Don't set a row property of a TStringGrid to a fixed row!

Having spent hours trying to resolve a problem I only found the cause after starting to post this problem. It wasn't until I tried a simple test for the benefit of an example that I found the problem.

The problem that was happening was as follows:

I am having problems with the top row of the StringGrid duplicating itself. I populate the string grid through code initially on FormShow and it appears perfectly OK if I have FixedRows := 0;
If I have FixedRows := 1; then it mainly duplicates the fixed row but you cannot access the row.

It redraws/repaints itself correctly under the following conditions :
a) You edit the grid and tab off the first row which the user can select (3rd physical row), 1st row is Fixed, 2nd row is a duplicate of 1st and 3rd is the first scrollable ie row 1.
b) You have horizontal scrolling enabled and you scroll to the right.

I have 5 grids on 3 tabsheets. 2 have FixedRows := 0; and give me no problem. The other 3 have FixedRows := 1; and the problem appears to be when the StringGrid container has focus.
Example : I leave the form in design mode on tabsheet1, the grid on this tabsheet duplicates the top row. I look at the grids on tabsheets 2 and 3 and they appear OK. Then on Tabsheet 2 I do something to cause the grid to be rebuilt by my code and then this grid will now duplicate the top, even though it ran the same routine as it did on Formshow at the start, the only difference is the tabsheet containing the grid now is visible.

Answer : Set Row = 1; and NOT Row = 0;

 
I have had similar problems. I tend to use no fixed rows as it creates less hassle.




------------------------------------
There's no place like 127.0.0.1
------------------------------------
 
Are you using an 'ondrawcell' function, this is the only practical way to handle string grids.
Here are some points you might find useful..

The Col and Row values passed into the Ondrawcell function only retain their values for a very short time, create some local variables e.g. X and Y and assign the values of Row and Col to these on entry.
e.g
procedure TEmergiForm.emergidataDrawCell(Sender: TObject; Col, Row: Integer; Rect: TRect; State: TGridDrawState);
var c, r: integer;
begin
r := row;
c := Col;
etc..

If you dont use 'Ondrawcell' any windows opened over the grid will erase part of it, and you will have to handle redraws.

Note that 'DefaultDrawing' does not have to be false to use OnDrawCell, and you should only need this if you want to change the apperance of the grid radically.

Steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top