was ist neu ¦  programmier tips ¦  indy artikel ¦  intraweb artikel ¦  informationen ¦  links ¦  interviews
 sonstiges ¦  tutorials ¦  Add&Win Gewinnspiel

Tips (1541)

Dateien (137)
Datenbanken (90)
Drucken (35)
Grafik (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Mathematik (76)
Multimedia (45)
Oberfläche (107)
Objekte/
ActiveX (51)

OpenTools API (3)
Sonstiges (126)
Strings (83)
System (266)
VCL (242)

Tips sortiert nach
Komponente


Tip suchen

Tip hinzufügen

Add&Win Gewinnspiel

Werbung

27 Visitors Online


 
...den Cursor in einem Stringgrid positionieren?
Autor: Thomas Stutz
[ Tip ausdrucken ]  

Tip Bewertung (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;


 

Bewerten Sie diesen Tipp:

dürftig
ausgezeichnet


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