AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren

Stringgrid selection Problem !

Ein Thema von richard_boderich · begonnen am 1. Jul 2004 · letzter Beitrag vom 4. Jul 2004
 
Benutzerbild von sakura
sakura

Registriert seit: 10. Jun 2002
Ort: Unterhaching
11.413 Beiträge
 
Delphi 12 Athens
 
#7

Re: Stringgrid selection Problem !

  Alt 2. Jul 2004, 10:30
Okay, verstanden und ... gelöst.

Das ist schon etwas einfacher. Du mußt zwei Ereignisse abfangen. Einmal das OnSelectCell, um dem StringGrid mitzuteilen, daß sich die Auswahl grundlegend geändert hat, und einmal das OnDrawCell Ereigniss, um die Auswahl darzustellen.

Außerdem habe ich noch eine Methode geschrieben, welche ermittelt, ob sich eine Zelle (Spalte, Zeile) in der erweiterten Auswahl befindet.

Hier die drei Methoden und es geht.
Delphi-Quellcode:
type
  TForm1 = class(TForm)
    [...]
  private
    { Private declarations }
    function CellInRange(aGrid: TCustomDrawGrid; aCol, aRow: Integer): Boolean;
    [...]
  end;

// testen, ob sich eine bestimmte Zelle in der erweiterten Auswahl aufhält
function TForm1.CellInRange(aGrid: TCustomDrawGrid; aCol, aRow: Integer
    ): Boolean;
begin
  Result := False;
  if aRow < aGrid.Selection.Top then
    Exit;
  if aRow = aGrid.Selection.Top then
    if aCol < aGrid.Selection.Left then
      Exit;
  if aRow > aGrid.Selection.Bottom then
    Exit;
  if aRow = aGrid.Selection.Bottom then
    if aCol > aGrid.Selection.Right then
      Exit;
  Result := True;
end;

// die Ereignisroutinen
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
begin
  if Sender = nil then
    Exit;
  if not (Sender is TStringGrid) then
    Exit;
  with Sender as TStringGrid do
  begin
    // skip fixed columns
    if (ACol < FixedCols) or (ARow < FixedRows) then
      Exit;
    // select color
    if CellInRange(Sender as TStringGrid, ACol, ARow) then
    begin
      // selected cell
      Canvas.Brush.Color := clHighlight;
      Canvas.Font.Color := clHighlightText;
    end else begin
      // cell not selected
      Canvas.Brush.Color := clWindow;
      Canvas.Font.Color := clWindowText;
    end;
    // draw cell
    Canvas.TextRect(Rect, Rect.Left, Rect.Top, Cells[ACol, ARow]);
  end;
end;

procedure TForm1.StringGrid1SelectCell(Sender: TObject; ACol,
  ARow: Integer; var CanSelect: Boolean);
begin
  if Sender = nil then
    Exit;
  if not (Sender is TStringGrid) then
    Exit;
  with Sender as TStringGrid do
  begin
    Update;
    Invalidate;
  end;
end;
......
Lizbeth W.
Ich bin nicht zurück, ich tue nur so
  Mit Zitat antworten Zitat
 

Themen-Optionen Thema durchsuchen
Thema durchsuchen:

Erweiterte Suche
Ansicht

Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 23:31 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz