whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

44 Visitors Online


 
...position the caret in a Stringgrid?
Autor: Thomas Stutz
[ Print tip ]  

Tip Rating (10):  
     


{
  The following code allows you to position the caret
  in a cell (InplaceEditor) of a StringGrid.
  We need a Cracker class to access the InplaceEditor.

  Mit folgendem Code kann man den Cursor in einer Zelle
  (InplaceEditor) eines StringGrids positionieren.
  Hierfür brauchen wir eine "Cracker" Klasse, weil der
  InplaceEditor "protected" ist.
}

type
  
TGridCracker = class(TStringGrid);
  
{...}

implementation

{...}

procedure SetCaretPosition(Grid: TStringGrid; col, row, x_pos: Integer);
begin
  
Grid.Col := Col;
  Grid.Row := Row;
  with TGridCracker(Grid) do
    
InplaceEditor.SelStart := x_pos;
end;

// Get the Caret position from the focussed cell
// Ermittelt die Caret-Position der aktuellen Zelle
function GetCaretPosition(Grid: TStringGrid): Integer;
begin
  with 
TGridCracker(Grid) do
    
Result := InplaceEditor.SelStart;
end;

// Example / Beispiel:

// Set the focus on col 1, row 3 and position the caret at position 5
// Fokusiert die Zelle(1,3) und setzt den Cursor auf Position 5

procedure TForm1.Button1Click(Sender: TObject);
begin
  
StringGrid1.SetFocus;
  SetCaretPosition(StringGrid1, 1, 3, 5);
end;


 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners