我需要添加复制矩形选择的节点和列的功能,但我找不到任何方法来实际选择虚拟树视图中的多个列(在toFullRowSelect旁边).
我只是错过了一些东西吗?如果没有,是否有一个网格状多列选择支持的后代?
解决方法
因此经过一些测试后,我想出了以下内容,感谢DiGi的额外推动. DrawSelection不适用于此解决方案,因此需要禁用它.因为我不认为我很快就会再这样做,所以我没有写下属.
将toDisableDrawSelection,toExtendedFocus和toMultiSelect设置为True.
在适当的地方声明以下变量/属性:
StartSelectedColumn: integer; FirstSelectedColumn: integer; LastSelectedColumn: integer; Selecting: boolean;
更新以下事件:
onkeydown事件
if (not Selecting) and (Key = VK_SHIFT) then begin StartSelectedColumn := vtMain.FocusedColumn; FirstSelectedColumn := StartSelectedColumn; LastSelectedColumn := StartSelectedColumn; Selecting := true; end;
的onkeyup
if Key = VK_SHIFT then Selecting := false;
OnFocusChanged
if Selecting then begin if column < StartSelectedColumn then begin FirstSelectedColumn := column; LastSelectedColumn := StartSelectedColumn; end else if column > StartSelectedColumn then begin FirstSelectedColumn := StartSelectedColumn; LastSelectedColumn := column end else begin FirstSelectedColumn := column; LastSelectedColumn := column; end; end else begin StartSelectedColumn := column; FirstSelectedColumn := column; LastSelectedColumn := column; end;
OnBeforeCellPaint
if vtMain.Selected[node] and InRange(column,FirstSelectedColumn,LastSelectedColumn) then begin if vtMain.Focused then TargetCanvas.Brush.Color := vtMain.Colors.FocusedSelectionColor else TargetCanvas.Brush.Color := vtMain.Colors.UnfocusedSelectionColor; TargetCanvas.Brush.Style := bsSolid; TargetCanvas.FillRect(CellRect); end;
OnPaintText
if vtMain.Selected[node] and InRange(column,LastSelectedColumn) then begin if vtMain.Focused then TargetCanvas.Font.Color := clHighlightText else TargetCanvas.Font.Color := vtMain.Font.Color; end;