简体   繁体   中英

Delphi: auto scroll for String Grid

how to make an auto scroll for a String Grid?

A property "Row" or "TopRow" does not help if a String Grid is invisible (eg 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!

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.

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM