Announcement

Collapse
No announcement yet.

DBGrid: Fokusierte Zeile markieren (ohne RowSelect)

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • DBGrid: Fokusierte Zeile markieren (ohne RowSelect)

    Hallo beisammen,

    wie kann ich in einem DBGrid das Verhalten der Option RowSelect nachbilden?

    Ich möchte also, dass jede Zelle der aktuellen Zeile farblich markiert wird.

    Hier habe ich mal meine Routine DrawColumnCell beigefügt - ich habe nur noch keinen Parameter gefunden, der mir anzeigt, ob die aktuelle Zeile auch selektiert ist.

    Danke für jede Hilfe
    und schöne Feiertage

    Ralph

    <PRE>

    procedure TfmProPos.dbgPositionenDrawColumnCell(Sender: TObject;
    const Rect: TRect; DataCol: Integer; Column: TColumn;
    State: TGridDrawState);
    var
    BrushColor, FontColor: TColor;
    begin
    // ***************************************
    // Default-Farben
    // ***************************************
    BrushColor := clWindow;
    FontColor := clBlack;
    <p>
    // ***************************************
    // fokusierte Zeile markieren
    // ***************************************
    // if State = [gdFocused] then // funktioniert nicht
    // if State = [gdSelected] then // funktioniert nicht
    if <b>???</b> then
    begin
    BrushColor := clLtGray;
    FontColor := clBlack;
    end;
    <p>
    // ***************************************
    // evtl. erste Spalte einfärben
    // ***************************************
    if Column.ID = 0 then
    begin
    case qyProPosAnzeigeTyp.Value of
    2: BrushColor := clYellow;
    3: BrushColor := clRed;
    4: BrushColor := clFuchsia;
    5: BrushColor := clLime;
    end;
    end;
    <p>
    // ***************************************
    // Grid entsprechend einfärben
    // ***************************************
    dbgPositionen.Canvas.Brush.Color := BrushColor;
    dbgPositionen.Canvas.Font.Color := FontColor;
    dbgPositionen.DefaultDrawColumnCell(Rect, Datacol, Column, State);
    end;

    </PRE>

  • #2
    Hallo,

    <pre>
    if State = [gdSelected]
    </pre> ist falsch.

    Richtig ist: <pre>if gdSelected in State then </pre>

    Gruß Ul

    Comment


    • #3
      Hallo zusammen,

      das Problem hatte ich mal bei einem DBGrid, bei dem RowSelect auf keinen Fall auf True setzen konnte. Der Trick besteht darin kurz eine neue, von DBGrid abgeleitete Komponente zu erzeugen, so dass man dann über Typecasting auf die protected-Elemente von DBGrid zugreifen kann. Das ganze sieht dann ungefähr so aus:

      type
      TMyDBGrid = class(TCustomDBGrid);

      ......

      procedure TBlabla.grdHubbaBubbaDrawColumnCell(Sender: TObject;
      const Rect: TRect; DataCol: Integer; Column: TColumn;
      State: TGridDrawState);
      var
      Nr : Integer;
      begin
      //über das Typcasting TMyDBGrid -> TCustomDBGrid erlange ich Zugriff auf die
      //protected-Elemente von TCustomDBGrid
      with TMyDBGrid(Sender) do
      begin
      //-1 weil die Titelzeile mit im Grid steckt
      if TDataLink(DataLink).ActiveRecord=Row-1
      then
      begin
      with Canvas do
      begin
      Brush.Color := clYellow;
      Font.Color := clBlack;
      Font.Style := [fsBold];
      DefaultDrawColumnCell(Rect,DataCol,Column,State);
      end;
      end;
      end;
      end;

      viel Spass
      Stefa

      Comment


      • #4
        hups,

        sorry, ich habe die Formatierungen vergessen, verzichte aber auf nochmaliges Einstelle

        Comment


        • #5
          Uli,

          vielen Dank - aus dem Kopf behaupte ich mal, dass Deine Syntax einen Compilerfehler provoziert hat... darum dieses etwas ungewöhnliche Konstrukt.

          Ich werde es aber natürlich nochmals mit Deinem Vorschlag versuchen.

          Ralp

          Comment


          • #6
            Stefan,

            danke für Deine Antwort! Ich werde das mal versuchen... so etwas in der Art habe ich tatsächlich gesucht.

            Ralp

            Comment

            Working...
            X