2

how to make an auto scroll for a String Grid?

A property "Row" or "TopRow" does not help if a String Grid is invisible (e.g. on a hidden frame): no cells are selected. If to show it - it's cell becomes selected and "Row"/"TopRow" works.

Try. In a design time. A String Grid: 100 rows, visible:=false. On a button's click:

StringGrid1.Row := 99; 
StringGrid1.Visible := true. 

And return "visible" to true for the String Grid. Please see a difference.

Thanks!

Gabriel
  • 20,797
  • 27
  • 159
  • 293
maxfax
  • 4,281
  • 12
  • 74
  • 120

2 Answers2

3

Call HandleNeeded before setting the row if the string grid has never shown before:

StringGrid1.HandleNeeded;
StringGrid1.Row := 99;

// later
StringGrid1.Visible := True;


Initially invisible, the string grid window has not been created yet. Setting the row sets the property but cannot scroll a non-existing window.

Sertac Akyuz
  • 54,131
  • 4
  • 102
  • 169
  • The handle for a WinControl is the window handle, to have the window handle the VCL has to create the window of the control. – Sertac Akyuz Jul 20 '11 at 21:30
  • Bug!!! Before "StringGrid1.Row := 99" I change columns' width. If to use "HandleNeeded" then Grid Lines have old positions and new ones at one time; text is showed incorrectly !!! – maxfax Jul 21 '11 at 03:10
  • @maxfax - Couldn't duplicate with a simple test, sorry. StringGrid1.Invalidate helps? – Sertac Akyuz Jul 21 '11 at 06:09
0

When i try the following code it seems to work the same in all three cases, visible, unvisiblae and unvisible parent:

  StringGrid1.TopRow := 5;
  showmessage(inttostr(StringGrid1.TopRow)); //shows 5
  StringGrid1.Visible := false;
  StringGrid1.TopRow := 2;
  showmessage(inttostr(StringGrid1.TopRow)); //shows 2
  StringGrid1.Parent.Visible := false;
  StringGrid1.TopRow := 1;
  showmessage(inttostr(StringGrid1.TopRow)); //shows 1

Is that what you mean?

CloudyMarble
  • 36,908
  • 70
  • 97
  • 130
  • Try. In a design time. A String Grid: 100 rows, visible:=false. On a button's click: StringGrid1.Row := 99; StringGrid1.Visible := true. And then return "visible" to true for the String Grid. Please see difference. – maxfax Jul 20 '11 at 07:22