Autor Beitrag
Christoph Englmann
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 276



BeitragVerfasst: Do 06.04.06 17:41 
hallo,

durchlaufe eine Treeview und möchte das entsprechende Item dann selektieren und mittig in der treeview haben...

code:

ausblenden Delphi-Quelltext
1:
2:
3:
        TreeViewLeft.Items.Item[i].Selected := true;
        y := round(TreeViewleft.Height/2);
        TreeViewleft.ScrollBy(0,y);


leider hat die scrollby funktion keinerlei einfluss:
das markierte element ist immernoch unten am ende der treeview.... :-(
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Do 06.04.06 20:02 
Hallo,

die Methode ScrollBy verschiebt nur den Bildausschnitt.

Es geht sicherlich eleganter, :?
aber damit(D3) wird der selectierte Node etwa in die Mitte gescrollt:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
procedure SetNodeHalf(TV: TTreeView);
var aRect : TRect;
    Itemh, halfH, z : Integer;
begin
  with TV do
    begin
    Items.BeginUpdate;
    aRect := Selected.DisplayRect(True);
    Itemh := aRect.Bottom-aRect.Top; //Höhe Item
    halfH := round(Height/2); //halbe TreeViewHöhe
    if aRect.Top > halfH then
      begin
      for z := 0 to round((aRect.Top-halfH)/Itemh) do
        Perform(WM_VSCROLL,SB_LINEDOWN,0);
      end
      else
        for z := 0 to round((halfH-aRect.Top-Itemh)/Itemh) do
          Perform(WM_VSCROLL,SB_LINEUP,0);
    Items.EndUpdate;
    end;
end;

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
Christoph Englmann Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 276



BeitragVerfasst: Fr 07.04.06 14:02 
hallo,

erstmal danke für die antwort.

prinzipiell funktioniert das verschieben schon, nur leider wird der aktivierte Node nicht in die mitte sondern sogar über die sichtbare treeview hinaus nach oben verschoben...
(aRect.Bottom=512 und aRect.Top =578)

die SetNodeHalf procedure wird erst zum schluss des on Show ereignises der hauptform auf welcher sich die treeview befindet aufgerufen => zu diesem zeitpunkt muesste die treeview also eigentlich schon die letztendlicht größe haben....

danke
christoph