TVirtualStringTree.如何通过单个确认检查节点及其子节点? [英] TVirtualStringTree. How to check a node and its children with a single confirmation?

查看:214
本文介绍了TVirtualStringTree.如何通过单个确认检查节点及其子节点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类型为TVirtualStringTree的组件.选项toCheckSupport已启用.由于需要传播,因此还启用了与检查状态传播有关的选项.我要实施带有确认的检查节点(确定要检查...吗?").不幸的是,如果启用了传播选项,则会触发事件OnCheckOnChecking,包括子节点.因此,将消息放在事件过程中会使它重复显示.您是否知道如何通过一次确认来检查节点及其子节点?

I have a component of type TVirtualStringTree. The option toCheckSupport is enabled. The options related to the propagation of checkstates are also enabled, because the propagation is needed. I want to implement checking a node with a confirmation ("Are you sure you want to check... ?"). Unfortunately, if the options for propagation are enabled, the events OnCheck and OnChecking are triggered including for the child nodes. Therefore, placing the message in the event procedures make it show repeatedly. Do you have any idea how to check a node and its child nodes with a single confirmation?

我想到了手动检查,即用户想要检查树中的一个节点(因此检查所有节点的后代),并且只被要求确认一次.如果用户要检查叶子,则进行确认检查很简单:将节点还原到先前的状态就足够了.

I think of manual checking, i.e. the user wants to check a node in the tree (and hence all the node's descendants) and is asked for confirmation only once. Checking with confirmation is simple if the user wants to check a leaf: it is sufficient to restore the node to the previous state.

procedure TMyForm.VSTChecked(Sender: TBaseVirtualTree; Node: PVirtualNode);
begin
  if Node.CheckState = csCheckedNormal then
  begin
    if not VST.HasChildren[Node] then
    begin
      if MessageDlg('Are you sure you want to check?', mtConfirmation,
        mbYesNo, 0) <> mrYes then
      begin
        Node.CheckState := csUncheckedNormal;
        PropagateCheckState(VST, Node); // From Node's parent to the root 
      end;
    end;
  end;
end;

我考虑过使用OnNodeClick来确定用户已检查的确切节点,并且(如在我的应用程序中,重要数据位于叶子中)有关记住叶子的先前检查状态以进行恢复的想法他们.会导致一个好的解决方案吗?

I thought about using OnNodeClick in order to identify the exact node that became checked by the user, and (as in my application the significant data are in leaves) about remembering the previous check states of the leaves in order to restore them. Would it lead to a good solution?

推荐答案

使用OnMouseDown事件可获取有关鼠标单击的通知.如果是TMouseButton.mbLeft,请调用GetHitTestInfoAt(),并检查THitInfo.HitPositions中是否包含THitPositions.ctCheckBox.如果是这样,THitInfo.HitNode包含相应的节点.然后,您可能会显示确认对话框,并将结果保存到成员变量中,您可以在OnChecking事件中使用该变量来允许或禁止更改检查状态.

Use the OnMouseDown event to get notified about a mouse click. If it's TMouseButton.mbLeft call GetHitTestInfoAt() and check if THitPositions.ctCheckBoxis included in THitInfo.HitPositions. If so, THitInfo.HitNodecontains the corresponding node. You may then show the confirmation dialog and save the result in a member variable, that you can use in the OnChecking event to allow or disallow the change of the check state.

这篇关于TVirtualStringTree.如何通过单个确认检查节点及其子节点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆