VirtualTreeview使用说明
很好用的一个列表控件,可以用来代替Delphi自带的ListView和TreeView,而且也一直在更新,目前已经支持最新的XE2
:www.soft-gems
SVN地址:lecode/svn/trunk
基本的使用方法就不多说了,可以看看Demo,或者百度一下还是有些教程的。我这里只记录一些属性方法等,方便查阅
【属性】
EditDelay = 单元格编辑响应时间
HintAnimation = Hint动画效果
HintMode = Hint显示方式
LineMode = 网格线条模式
LineStyle = 网格线条样式
Header > AutoSizeIndex = 自适应宽度的列索引
Header > Options > hoAutoResize = 列自适应宽度开关
Header > Options > hoColumnResize = 是否可以自由调整列宽
Header > Options > hoDblClickResize = 双击分界线自动改变列度
Header > Options > hoDrag = 是否支持拖拽移动
Header > Options > hoHotTrack = 高亮显示当前列
Header > Options > hoHeightResize = 是否可以自由调整列高
TreeOptions > AutoOptions > toAutoExpand = 单击展开节点并收起其他节点
TreeOptions > AutoOptions > toAutoTristateTracking = 三态复选框自适应选择,即子节点被选择后父节点Check状态改变
TreeOptions > MiscOptions > toCheckSupport = 是否显示复选框。还需要设置节点的CheckType属性TreeOptions > MiscOptions > toEditable = 是否允许单击编辑单元格
TreeOptions > MiscOptions > toFullRepaintOnResize = 控件大小改变时刷新显示数据
TreeOptions > MiscOptions > toToggleOnDblClick = 双击展开节点
TreeOptions > PaintOptions > toHideSelection = 隐藏选择焦点
TreeOptions > PaintOptions > toHotTrack = 当前行是否显示下划线
TreeOptions > PaintOptions > toShowDropmark = 拖拽时是否显示插入标记
TreeOptions > PaintOptions > toShowRoot = 是否显示父节点展开按钮
TreeOptions > PaintOptions > toShowHorzGridLines = 水平网格线开关
TreeOptions > PaintOptions > toShowTreeLines = 父节点与子节点的连接线
TreeOptions > PaintOptions > toShowVertGridLines = 垂直网格线开关
TreeOptions > PaintOptions > toThemeAware = 应用系统主题
TreeOptions > PaintOptions > toAlwaysHideSelection = 总是隐藏选择
TreeOptions > PaintOptions > toChildrenAbove = 父节点处于子节点下方
TreeOptions > SelectionOptions > toDisableDrawSelection = 框选开关
TreeOptions > SelectionOptions > toExtendedFocus = 是否允许Cloumn>0的单元格有焦点(有焦点的时候才能编辑)
TreeOptions > SelectionOptions > toFullRowSelect = 整行选择
TreeOptions > SelectionOptions > toMultiSelect = 是否可以多选
TreeOptions > SelectionOptions > toRightClickSelect = 右键是否可以选择
TreeOptions > SelectionOptions > toSimpleDrawSelection = 框选时只要该行处于框内即可被选择
TreeOptions > StringOptions > toShowStaticText = 是否显示静态文本(在节点正文后面显示的字符,静态文本不能编辑)
【方法】
TopNode = 设置列表顶部的节点,可以用来定位节点行
ScrollIntoView = 设置滚动条位置,可以用来定位节点行
【事件】
OnChange = 焦点改变时
OnCreateEditor = 设置某单元格的编辑框样式,比如TEdit,TComboBox等等。需要自己实现IVTEditLink接口,具体参看Advanced这个Demo
OnExpanded = 节点展开后触发
OnCollapsed = 节点收起后触发
OnPaintText = 设置单元内容字体效果,也可以画进度条等
OnHotChange = 热点节点改变时触发,也就是鼠标悬停时
单元格纵向位置及单元格高度
procedure TForm1.VST1InitNode(Sender: TBaseVirtualTree; ParentNode, Node: PVirtualNode;
var InitialStates: TVirtualNodeInitStates);
begin
Node := 20; //纵向位置
Sender.NodeHeight[Node] := 20; //单元格高度
end;
动态调整列宽度
procedure TForm1.VST1Resize(Sender: TObject);
begin
VST1.Header.Columns[1].Width := VST1.Width - VST1.Header.Columns[1].Left - 25;
end;
如何设置滚动条的位置单元格字体
procedure TPropertiesForm.VST3PaintText(Sender: TBaseVirtualTree; const TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType);
var
Data: PPropertyData;
begin
// Make the root nodes underlined and draw changed nodes in bold style.
if Node.Parent = Sender.RootNode then
TargetCanvas.Font.Style := [fsUnderline]
else
begin
Data := Sender.GetNodeData(Node);
if Data.Changed then
TargetCanvas.Font.Style := [fsBold]
else
TargetCanvas.Font.Style := [];
end;
end;
单元格颜
procedure TGridForm.VST5BeforeCellPaint(Sender: TBaseVirtualTree; TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex; CellPaintMode: TVTCellPaintMode; CellRect: TRect; var ContentRect: TRect);
begin
// Fill random cells with our own background, but don't touch the currently focused cell.
if Assigned(Node) and ((Column <> Sender.FocusedColumn) or (Node <> Sender.FocusedNode)) and
((Column - 2) = (Integer(Node.Index) mod (Sender.Header.Columns.Count - 1))) then
begin
TargetCanvas.Brush.Color := $E0E0E0;
TargetCanvas.FillRect(CellRect);
end;
end;
隐藏行
VST1.IterateSubtree(nil, HideNodes, Pointer(ItemIndex), [], True);
procedure TVisibilityForm.HideNodes(Sender: TBaseVirtualTree; Node: PVirtualNode; Data: Pointer; var Abort: Boolean);
begin
Sender.IsVisible[Node] := False;
end;
单元格编辑
1.调用Editors单元
2.消息处理函数
const
WM_STARTEDITING = WM_USER + 2000; //消息处理函数
procedure TForm1.WMStartEditing(var Message: TMessage);
var
Node: PVirtualNode;
Sender: TBaseVirtualTree;
begin
Sender := TBaseVirtualTree(Message.WParam);
//Node := Pointer(Message.WParam);
Node := Sender.FocusedNode;
if Assigned(Node) then //默认对当前选中行进行编辑
Sender.EditNode(Node, Message.LParam); //指定待编辑的列
end;
3.触发编辑事件
TreeOptions := [toExtendedFocus,toFullRowSelect,toRightClickSelect];
procedure TForm1.VST1FocusChanged(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex); begin
with Sender do
begin
if Assigned(Node) and not (tsIncrementalSearching in TreeStates) then
begin
PostMessage(Self.Handle, WM_STARTEDITING, Integer(Sender), Column);
end;
end;
end;
4.编辑事件控制
procedure TForm1.VST1Editing(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex;
var Allowed: Boolean);
var
Data: PPropertyData;
begin
with Sender do
begin
Data := GetNodeData(Node);
Allowed := (Data.ValueTypes[Column] <> vtNone);
end;
end;
5.创建编辑框
procedure TForm1.VST1CreateEditor(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex; out EditLink: IVTEditLink);
begin
EditLink := TPropertyEditLink.Create;
end;
6.内容改变
procedure TForm1.VST1PaintText(Sender: TBaseVirtualTree; const TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType);
var
Data: PPropertyData;
begin
Data := Sender.GetNodeData(Node);
if Data.Changeds[Column] then
TargetCanvas.Font.Style := [fsBold]
else
TargetCanvas.Font.Style := [];
end;
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论