Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   Delphi Images in VirtualStringTree (VST) (https://www.delphipraxis.net/135292-images-virtualstringtree-vst.html)

larsk81 8. Jun 2009 16:31


Images in VirtualStringTree (VST)
 
Ich habe ein Problem, das ich einfach nicht gelöst bekomme. Ich probiere schon seit zwei Tagen.
Ich nutze einen VST und möchte gerne z.B. in column 2 vor jeden Eintrag eine Grafik anzeigen lassen, was mit

Delphi-Quellcode:
procedure TForm1.VSTGetImageIndex(Sender: TBaseVirtualTree; Node: PVirtualNode;
  Kind: TVTImageKind; Column: TColumnIndex; var Ghosted: Boolean;
  var ImageIndex: Integer);
begin
ImageIndex:=0;                    
end;
ja auch geht (mit dem Code oben wird das Bild 0 der zugeteilten ImageList vor jedem Feld angezeigt, in jeder Zeile und jeder Spalte).

Jetzt ist es so: wenn jemand auf ein Feld, z.B. von column 2, klickt, wird per OnClick etwas ausgeführt. An genau dieser Stelle würde ich gerne auch das Bild des Eintrags auf den geklickt wurde ändern (das Bild 1 aus der ImageList laden).
Geht das? Oder kann man ImageIndex nur in OnGetImageIndex, und nicht in OnClick, ändern?

Wäre riesig dankbar für Hilfe

DP-Maintenance 8. Jun 2009 16:33

DP-Maintenance
 
Dieses Thema wurde von "Phoenix" von "Sonstige Fragen zu Delphi" nach "VCL / WinForms / Controls" verschoben.
Frage zu einer Komponente...

Nighthawk1310 8. Jun 2009 17:59

Re: Images in VirtualStringTree (VST)
 
Liste der Anhänge anzeigen (Anzahl: 1)
Hinterlege den ImageIndex für einen Node in Deinen NodeDaten in einer Variable oder mache den
ImageIndex von anderen Variablen in Deinen NodeDaten "abhängig".

Lass dann deine Images im AfterCellPaint des VST zeichnen. Bei der Methode braucht dem VST übrigens
keine Imagelist zugeordnet zu sein.

Bsp:
Delphi-Quellcode:
        //User online
        if (pNodeDataUser.bOnline and (not pNodeDataUser.bPaused)) then
           frmMain.imgMain.Draw(TargetCanvas, CellRect.Left + 4, CellRect.Top + 3, 8);

        //User paused
        if (pNodeDataUser.bOnline and pNodeDataUser.bPaused) then
           frmMain.imgMain.Draw(TargetCanvas, CellRect.Left + 4, CellRect.Top + 3, 9);

        //User sick
        if (pNodeDataUser.bSick and (not pNodeDataUser.bOnline)) then
           frmMain.imgMain.Draw(TargetCanvas, CellRect.Left + 4, CellRect.Top + 3, 26);
        //User holiday

        if (pNodeDataUser.bHoliDay and (not pNodeDataUser.bOnline)) then
            frmMain.imgMain.Draw(TargetCanvas, CellRect.Left + 4, CellRect.Top + 3, 27);
       
        //User idle
        if (pNodeDataUser.bOnline and pNodeDataUser.bIdle) then
           frmMain.imgMain.Draw(TargetCanvas, CellRect.Left + 23, CellRect.Top + 3, 6);
Auf diese Art und Weise kannst du die Images aus eine Imagelist oder aus einem TImage in den VST Zeichnen.
Die Positionsberechnung liegt in dem Fall allerdings bei Dir.


Anbei noch ein Screenshot aus einem meiner Programme.
Die Symbole benutze ich in meinem Beispiel nicht nur als Anzeige, sondern auch als Schaltflächen
Die Abfrage des Klicks erfolgt dabei im MouseUp des VST's:


Delphi-Quellcode:
         //X und Y werden vom VST übergeben
         xNode := vstMainList.GetNodeAt(X, Y);

         if xNode.Dummy = 98 then
            begin
            CellRect  := vstMainList.GetDisplayRect(xNode, 0, False);

            //Working/Paused
            if ((X >= CellRect.Left + 2) and (X <= CellRect.Left + 22 )) and
               ((Y >= CellRect.Top + 4) and (Y <= CellRect.Top + 19 )) then
               SetPausedWorking(xNode);

            //CoachingMode
            if ((X >= CellRect.Left + 42) and (X <= CellRect.Left + 60 )) and
               ((Y >= CellRect.Top + 5) and (Y <= CellRect.Top + 19 )) then
               SetCoachingMode(xNode);

            //View
            if ((X >= CellRect.Left + 62) and (X <= CellRect.Left + 80 )) and
               ((Y >= CellRect.Top + 5) and (Y <= CellRect.Top + 19 )) then
               ShowMessage('Nicht implementiert');

            //Talk/Write
            if ((X >= CellRect.Left + 82) and (X <= CellRect.Left + 102 )) and
               ((Y >= CellRect.Top + 5) and (Y <= CellRect.Top + 19 )) then
               ShowMessage('Talk/Write');

            //Refresh
            if ((X >= CellRect.Left + 102) and (X <= CellRect.Left + 120 )) and
               ((Y >= CellRect.Top + 5) and (Y <= CellRect.Top + 19 )) then
               RefreshUser(xNode);
            end;
Je nachdem wie die Variablen in meinen NodeDaten belegt sind lasse ich ein anderes Symbol zeichnen.

Ich hoffe, dass Dir das weiterhilft

larsk81 9. Jun 2009 00:07

Re: Images in VirtualStringTree (VST)
 
Herzlichen Dank für die Antwort! Problem gelöst 8)


Alle Zeitangaben in WEZ +1. Es ist jetzt 04:58 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz