delphiscrollbarvirtualtreeviewtvirtualstringtree

How to make VirtualStringTree scrollbar visible?


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


Solution

  • 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?