0

I placed one VirtualStringTree(VST1) on form1 and added some data in it. The vertical scrollbar is visible regardless of the number of nodes and I did not do anything about default properties of node height. I then copied VST1 to form2 and named it as VST2 and there the scrollbar of the VST2 is no longer visible. I changed VST2's parent control and align property (I tested many times and can not remember the sequence of changing properties of align and its parent), I do not know how the scrollbar at last is shown. I then copied the VST2 to form3 and named it as VST3. And now, no matter how I tested, its vertical scrollbar can not be seen when data in VST3 is beyond its window view.

There are too many properties of VST, what properties should I set?

edit:

// vt is on form1, scrollbaroption.alwaysvisible:=false;
//  and vt can show vertical scrollbar,

object vt: TVirtualStringTree 
      Left = 1
      Top = 1
      Width = 353
      Height = 301
      Hint = 'Click header to sort'
      Align = alClient
      Header.AutoSizeIndex = 0
      Header.DefaultHeight = 17
      Header.Font.Charset = DEFAULT_CHARSET
      Header.Font.Color = clWindowText
      Header.Font.Height = -11
      Header.Font.Name = 'MS Sans Serif'
      Header.Font.Style = []
      Header.Options = [hoColumnResize, hoDrag, hoShowSortGlyphs, hoVisible]
      Indent = 3
      ParentShowHint = False
      ShowHint = True
      TabOrder = 3
      TreeOptions.MiscOptions = [toAcceptOLEDrop, toFullRepaintOnResize, toInitOnSave, toToggleOnDblClick, toWheelPanning]
      TreeOptions.PaintOptions = [toShowRoot, toThemeAware, toUseBlendedImages]
      TreeOptions.SelectionOptions = [toFullRowSelect, toMultiSelect, toRightClickSelect]
      OnChange = vtChange
      OnCompareNodes = vtCompareNodes
      OnFocusChanged = vtFocusChanged
      OnFreeNode = vtFreeNode
      OnGetText = vtGetText
      OnGetNodeDataSize = vtGetNodeDataSize
      OnHeaderClick = vtHeaderClick
      OnLoadNode = vtLoadNode
      OnSaveNode = vtSaveNode
      Columns = <
        item
          Position = 0
          Width = 168
          WideText = 'Type'
        end
        item
          Position = 1
          Width = 80
          WideText = 'Frequency'
        end
        item
          Position = 2
          Width = 80
          WideText = 'Percent'
        end
        item
          CheckBox = True
          Position = 3
          Width = 80
          WideText = 'Rank'
        end
        item
          Position = 4
          Width = 80
          WideText = 'Length'
        end
        item
          Position = 5
          WideText = 'Syllables'
        end
        item
          Position = 6
        end>
    end
  end


//tfvt is on form2, scrollbaroption.alwaysvisible:=true;
// I tested both scrollbaroption.alwaysvisible:=true and false
// yesterday it showed scrollbar, today it does not.
// tfvt does not show vertical scrollbar.

      object tfvt: TVirtualStringTree
        Left = 1
        Top = 138
        Width = 737
        Height = 227
        Hint = 'Click header to sort'
        Align = alClient
        Header.AutoSizeIndex = 0
        Header.DefaultHeight = 17
        Header.Font.Charset = DEFAULT_CHARSET
        Header.Font.Color = clWindowText
        Header.Font.Height = -11
        Header.Font.Name = 'MS Sans Serif'
        Header.Font.Style = []
        Header.Options = [hoColumnResize, hoDrag, hoShowSortGlyphs, hoVisible]
        Indent = 3
        ParentShowHint = False
        ScrollBarOptions.AlwaysVisible = True
        ShowHint = True
        TabOrder = 2
        TreeOptions.MiscOptions = [toAcceptOLEDrop, toFullRepaintOnResize, toInitOnSave, toToggleOnDblClick, toWheelPanning]
        TreeOptions.PaintOptions = [toShowRoot, toThemeAware, toUseBlendedImages]
        TreeOptions.SelectionOptions = [toFullRowSelect, toMultiSelect, toRightClickSelect]
        OnChange = tfvtChange
        OnCompareNodes = tfvtCompareNodes
        OnFocusChanged = tfvtFocusChanged
        OnFocusChanging = tfvtFocusChanging
        OnFreeNode = tfvtFreeNode
        OnGetText = tfvtGetText
        OnGetNodeDataSize = tfvtGetNodeDataSize
        OnHeaderClick = tfvtHeaderClick
        OnLoadNode = tfvtLoadNode
        OnSaveNode = tfvtSaveNode
        Columns = <
          item
            Position = 0
            Width = 80
          end
          item
            Position = 1
            Width = 80
          end
          item
            Position = 2
            Width = 80
          end
          item
            CheckBox = True
            Position = 3
            Width = 80
          end
          item
            Position = 4
            Width = 80
          end
          item
            Position = 5
            Width = 80
          end
          item
            Position = 6
            Width = 80
          end>
      end
    end
  end
end

//  kwicvt is on form3, scrollbaroption.alwaysvisible:=true;
// I tested both scrollbaroption.alwaysvisible:=true and false
//  Now kwicvt does not show vertical scrollbar.
// 

object kwicvt: TVirtualStringTree
      Left = 32
      Top = 24
      Width = 433
      Height = 317
      Hint = 'Click header to sort'
      Header.AutoSizeIndex = 0
      Header.DefaultHeight = 17
      Header.Font.Charset = DEFAULT_CHARSET
      Header.Font.Color = clWindowText
      Header.Font.Height = -11
      Header.Font.Name = 'MS Sans Serif'
      Header.Font.Style = []
      Header.Options = [hoColumnResize, hoDrag, hoShowSortGlyphs, hoVisible]
      Indent = 3
      ParentShowHint = False
      ShowHint = True
      TabOrder = 0
      TreeOptions.AnimationOptions = [toAnimatedToggle]
      TreeOptions.MiscOptions = [toAcceptOLEDrop, toFullRepaintOnResize, toInitOnSave, toToggleOnDblClick, toWheelPanning]
      TreeOptions.PaintOptions = [toShowRoot, toThemeAware, toUseBlendedImages]
      TreeOptions.SelectionOptions = [toFullRowSelect, toMultiSelect, toRightClickSelect]
      OnChange = kwicvtChange
      OnCompareNodes = kwicvtCompareNodes
      OnFocusChanged = kwicvtFocusChanged
      OnFreeNode = kwicvtFreeNode
      OnGetText = kwicvtGetText
      OnGetNodeDataSize = kwicvtGetNodeDataSize
      OnHeaderClick = kwicvtHeaderClick
      OnLoadNode = kwicvtLoadNode
      OnSaveNode = kwicvtSaveNode
      Columns = <
        item
          Position = 0
          Width = 80
        end
        item
          Alignment = taRightJustify
          Position = 1
          Width = 80
        end
        item
          Alignment = taCenter
          Position = 2
          Width = 80
        end
        item
          CheckBox = True
          Position = 3
          Width = 80
        end
        item
          Position = 4
          Width = 80
        end
        item
          Position = 5
          Width = 80
        end
        item
          Position = 6
          Width = 80
        end>
    end

[Edit]:

Thank ain first.

I tested carefully and found that if I call the same function for more than once, from the second time on, that virticalscrollbar will appear. Something like:

function fill;
begin
// filling VST;
end;

function button1click;
begin
fill;
end;

I click button1 for the first time, verticalscrollbar does not appear; if for the second time or more, it shows perfectly.

Why?, how to solve it?

Thanks

Warren
  • 795
  • 1
  • 10
  • 19
  • BTW what version of delphi and what version of virtualtree? – ain Sep 19 '11 at 12:03
  • @ain, Delphi 7. virtualtreeview 4.87 – Warren Sep 19 '11 at 14:00
  • @ain, I posted 3 vst text. please have a look. – Warren Sep 19 '11 at 15:17
  • I tested the DFM definition of the `kwicvt` you posted and as soon as I did set the `RootNodeCount` to 50 in Object Inspector the scrollbars did appear. I'm using D2010 and VT 5.0 though... – ain Sep 19 '11 at 23:14
  • @ain, thanks so much. I was not at my desk for 2 days. Your comment prompted me to add rootnodecount in filling VST. Now I am closer to solution. Please look at my Edit. – Warren Sep 22 '11 at 03:28
  • Problem seems to be that you use `AddChild()` for adding **all** the nodes. The VT way to add nodes is to set the `RootNodeCount` to desired number and then handle `OnInitNode` and `OnInitChildren` events - thats what makes VT "virtual." – ain Sep 22 '11 at 08:30

1 Answers1

2

The scrollbar options of the VirtualTree is set via ScrollBarOptions property. Check the ScrollBarOptions.ScrollBars value - perhaps it is ssNone in VST3 and thats why there is no scrollbars?

ain
  • 22,394
  • 3
  • 54
  • 74
  • Thanks, but it is set ssboth. I do not know why? – Warren Sep 19 '11 at 11:17
  • Hmm, do you have enough nodes in the tree, so that scrollbar should be visible? Does it make difference when you set `ScrollBarOptions.AlwaysVisible := True`? – ain Sep 19 '11 at 11:24
  • thanks, scrollbaroption.alwaysvisible is true. The view mode of the VST is list. I filled about 1000 records. If I added vst3.FocusedNode:=vst3.GetLast(nil, false) at the end of the filling fucntion, the last record can be seen, but the scrollbar is still not visible. – Warren Sep 19 '11 at 11:33
  • 1
    Sorry, I'm running out of ideas right now... Does reloading the project help (ie close the project and open again)? If you drop new VT on form and set it's node count to some big number, does the scrollbar appear? Try to call `UpdateScrollbars(true)` in code, any difference? – ain Sep 19 '11 at 11:42
  • @Warren Since this appears hard to reproduce please give us a minimal code sample that reproduces the issue. That's your best bet right now. – David Heffernan Sep 19 '11 at 11:44
  • From the Form designer, right click on the form and choose _View as Text_ Try to compare all the VST properties between your different forms... – Whiler Sep 19 '11 at 11:53
  • @Whiler, Thanks, I am comparing properties of different forms. – Warren Sep 19 '11 at 12:09
  • @whiler, No, after checking two form texts. did not find reason. A little surprise is in form1, vst1 ScrollBarOptions.AlwaysVisible := false but it is always show the scrollbar.There IS one time in vst3 that did show scrollbar, but when I tested it again, it did not show. it seemed as if it is related to taborder. As I mentioned above, in form2 i did not know how it worked because i changed its parent controls and add other controls, this might changed the tab order. But i changed taborder of vst3, it does not show scrollbar. It is weird. – Warren Sep 19 '11 at 13:58
  • @Warren the code snipet you posted isn't really usefull, replace it with the fragment from the DFM showing how th VST is set up. – ain Sep 19 '11 at 14:04
  • As it seems to be the same... try to move the object in the dfm.. take care of the indentation to take only this object and children, and stay in the same parent.... if it's on the form, try to put it on the beginning, at the end, ... I have this idea, because I notice a weird issue with my components... even if I change the taborder, the order when I tab is not good: it follows the creation order like it is in the dfm... so maybe something weird with this creation order too... give it a chance ;o) – Whiler Sep 20 '11 at 22:22
  • Almost 6 years past and had the same problem. After adding new controls to the form, scrollbar disappeared. ctrl-x and crl-v the VST solved the problem. – Atys Apr 06 '17 at 11:06