Skip to content

Commit 403e36e

Browse files
Merge pull request #1287 from Npc8/master
Update GridDemo for ColumnHeaderSpanning Event
2 parents 58e0562 + 0e0ac49 commit 403e36e

File tree

2 files changed

+48
-6
lines changed

2 files changed

+48
-6
lines changed

Demos/Advanced/GridDemo.dfm

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,15 @@ object GridForm: TGridForm
44
ClientHeight = 474
55
ClientWidth = 745
66
Color = clBtnFace
7+
CustomTitleBar.CaptionAlignment = taCenter
78
Font.Charset = DEFAULT_CHARSET
89
Font.Color = clWindowText
910
Font.Height = -13
1011
Font.Name = 'Tahoma'
1112
Font.Style = []
12-
OldCreateOrder = False
1313
DesignSize = (
1414
745
1515
474)
16-
PixelsPerInch = 96
1716
TextHeight = 16
1817
object Label15: TLabel
1918
Left = 516
@@ -75,7 +74,7 @@ object GridForm: TGridForm
7574
'Virtual Tree Data')
7675
Colors.BorderColor = clWindowText
7776
Colors.HotColor = clBlack
78-
DefaultNodeHeight = 19
77+
DefaultNodeHeight = 17
7978
DragMode = dmAutomatic
8079
EditDelay = 300
8180
Font.Charset = ANSI_CHARSET
@@ -85,7 +84,7 @@ object GridForm: TGridForm
8584
Font.Style = []
8685
Header.AutoSizeIndex = 2
8786
Header.Background = clBtnShadow
88-
Header.Height = 20
87+
Header.Height = 17
8988
Header.Options = [hoColumnResize, hoDblClickResize, hoDrag, hoShowImages, hoVisible]
9089
Header.Style = hsFlatButtons
9190
HintMode = hmTooltip
@@ -99,7 +98,7 @@ object GridForm: TGridForm
9998
TreeOptions.AutoOptions = [toAutoDropExpand, toAutoScroll, toAutoScrollOnExpand, toAutoTristateTracking, toAutoChangeScale]
10099
TreeOptions.MiscOptions = [toAcceptOLEDrop, toEditable, toGridExtensions, toInitOnSave, toToggleOnDblClick, toWheelPanning]
101100
TreeOptions.PaintOptions = [toShowButtons, toShowDropmark, toShowHorzGridLines, toShowVertGridLines, toThemeAware, toUseBlendedImages]
102-
TreeOptions.SelectionOptions = [toMiddleClickSelect, toMultiSelect, toExtendedFocus]
101+
TreeOptions.SelectionOptions = [toExtendedFocus, toMiddleClickSelect, toMultiSelect]
103102
WantTabs = True
104103
OnAfterCellPaint = VST5AfterCellPaint
105104
OnBeforeCellPaint = VST5BeforeCellPaint
@@ -113,6 +112,7 @@ object GridForm: TGridForm
113112
OnStateChange = VST5StateChange
114113
Touch.InteractiveGestures = [igPan, igPressAndTap]
115114
Touch.InteractiveGestureOptions = [igoPanSingleFingerHorizontal, igoPanSingleFingerVertical, igoPanInertia, igoPanGutter, igoParentPassthrough]
115+
OnColumnHeaderSpanning = VST5ColumnHeaderSpanning
116116
Columns = <
117117
item
118118
Color = clWindow
@@ -167,6 +167,15 @@ object GridForm: TGridForm
167167
TabOrder = 2
168168
OnClick = AutoSpanCheckBoxClick
169169
end
170+
object DisplayFullNameCheckBox: TCheckBox
171+
Left = 518
172+
Top = 360
173+
Width = 153
174+
Height = 17
175+
Caption = 'Display Full Name'
176+
TabOrder = 3
177+
OnClick = DisplayFullNameCheckBoxClick
178+
end
170179
object TreeImages: TImageList
171180
Left = 22
172181
Top = 36

Demos/Advanced/GridDemo.pas

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ interface
1111

1212
uses
1313
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
14-
StdCtrls, VirtualTrees, ImgList, Menus, System.ImageList, VirtualTrees.BaseTree, VirtualTrees.Types;
14+
StdCtrls, VirtualTrees, ImgList, Menus, System.ImageList, VirtualTrees.BaseTree, VirtualTrees.Types,
15+
VirtualTrees.BaseAncestorVCL, VirtualTrees.AncestorVCL;
1516

1617
type
1718
TGridForm = class(TForm)
@@ -24,6 +25,7 @@ TGridForm = class(TForm)
2425
Edit1: TMenuItem;
2526
Label2: TLabel;
2627
AutoSpanCheckBox: TCheckBox;
28+
DisplayFullNameCheckBox: TCheckBox;
2729
procedure VST5BeforeCellPaint(Sender: TBaseVirtualTree; TargetCanvas: TCanvas; Node: PVirtualNode;
2830
Column: TColumnIndex; CellPaintMode: TVTCellPaintMode; CellRect: TRect; var ContentRect: TRect);
2931
procedure VST5BeforeItemErase(Sender: TBaseVirtualTree; TargetCanvas: TCanvas; Node: PVirtualNode; ItemRect: TRect;
@@ -44,6 +46,9 @@ TGridForm = class(TForm)
4446
procedure VST5FreeNode(Sender: TBaseVirtualTree; Node: PVirtualNode);
4547
procedure Edit1Click(Sender: TObject);
4648
procedure AutoSpanCheckBoxClick(Sender: TObject);
49+
procedure DisplayFullNameCheckBoxClick(Sender: TObject);
50+
procedure VST5ColumnHeaderSpanning(Sender: TVTHeader; Column: TColumnIndex;
51+
var Count: Cardinal);
4752
end;
4853

4954
var
@@ -185,6 +190,34 @@ procedure TGridForm.VST5BeforeCellPaint(Sender: TBaseVirtualTree; TargetCanvas:
185190

186191
//----------------------------------------------------------------------------------------------------------------------
187192

193+
procedure TGridForm.VST5ColumnHeaderSpanning(Sender: TVTHeader; Column: TColumnIndex; var Count: Cardinal);
194+
begin
195+
case Column of
196+
2:
197+
begin
198+
if DisplayFullNameCheckBox.Checked then
199+
begin
200+
//display header column 2 and 3 as ONE, we can also change the title here
201+
Count:= 2;
202+
Sender.Columns[Column].Text := 'Full Name';
203+
end else
204+
begin
205+
Count:= 1;
206+
Sender.Columns[Column].Text := 'First Name';
207+
end;
208+
end;
209+
end;
210+
end;
211+
212+
//----------------------------------------------------------------------------------------------------------------------
213+
214+
procedure TGridForm.DisplayFullNameCheckBoxClick(Sender: TObject);
215+
begin
216+
VST5.Refresh;
217+
end;
218+
219+
//----------------------------------------------------------------------------------------------------------------------
220+
188221
procedure TGridForm.VST5CreateEditor(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex;
189222
out EditLink: IVTEditLink);
190223

0 commit comments

Comments
 (0)