zoukankan      html  css  js  c++  java
  • 树形控件数据刷新前,保存及还原展开和选中状态

    void __fastcall TMainFrm::SaveExpandedNodes(TTreeView *ATree,
    std::map<AnsiString, Pointer>& g_TempList)
    {
    TTreeNode *ANode;
    TTreeNode *ANextNode;
    TTreeNodes *ANodes;
    ANodes = ATree->Items;
    g_TempList.clear();
    Cardinal FlagVal = 0;
    bool Expaned1 = false;
    bool Selected1 = false;
    ANode = ANodes->GetFirstNode();
    while (ANode)
    {
    Expaned1 = ANode->Expanded;
    Selected1 = ANode->Selected;
    if (Expaned1 || Selected1)
    {
    FlagVal = Selected1 << 1;
    FlagVal = FlagVal | Expaned1;
    AnsiString S = ANode->Text;
    g_TempList[S] = Pointer(FlagVal);
    }
    ANextNode = ANode->getFirstChild();
    while (ANextNode)
    {
    bool Expaned = ANextNode->Expanded;
    bool Selected = ANextNode->Selected;
    if (Expaned || Selected) {
    FlagVal = Selected << 1;
    FlagVal = FlagVal | Expaned;
    AnsiString S = ANode->Text + ANextNode->Text;
    g_TempList[S] = Pointer(FlagVal);
    }
    ANextNode = ANode->GetNextChild(ANextNode);
    }
    ANode = ANode->getNextSibling();
    }
    }

    void __fastcall TMainFrm::ExpandNodes(TTreeView *ATree, std::map<AnsiString,
    Pointer>& g_TempList)
    {
    TTreeNodes *ANodes = ATree->Items;
    TTreeNode *ANode = ANodes->GetFirstNode();
    TTreeNode *ANextNode;
    AnsiString S;
    Pointer P;
    Cardinal FlagVal;
    bool Expand, Selected;

    while (ANode)
    {
    S = ANode->Text;
    P = g_TempList[S];
    if (P != 0)
    {
    FlagVal = Cardinal(P);
    Expand = FlagVal & 1;
    Selected = (FlagVal >> 1) & 1;

    if (Expand)
    {
    ANode->Expand(true);
    }
    if (Selected)
    {
    ANode->Selected = true;
    }
    }
    ANextNode = ANode->getFirstChild();
    while (ANextNode)
    {
    S = ANextNode->Text;
    P = g_TempList[ANode->Text + S];
    if (P != 0)
    {
    FlagVal = Cardinal(P);
    Expand = FlagVal & 1;
    Selected = (FlagVal >> 1) & 1;
    if (Expand)
    {
    ANextNode->Expand(true);
    }
    if (Selected)
    {
    ANextNode->Selected = true;
    }
    }
    ANextNode = ANode->GetNextChild(ANextNode);
    }
    ANode = ANode->getNextSibling();
    }
    }

  • 相关阅读:
    [转]Delphi DLL的创建、静态 以及动态调用
    Delphi txt文件的操作(读取、写入)
    为什么要使用动态链接库(DLL)
    TStringGrid 实现下拉框
    Ryzen 4000'Vermeer' CPU和Radeon RX'Big Navi'图形卡
    AMD Ryzen 5000‘Cezanne’APU
    AMD–7nm “Rome”芯片SOC体系结构,支持64核
    ARM Cortex-M嵌入式C基础编程(下)
    ARM Cortex-M嵌入式C基础编程(上)
    基于ARM Cortex-M的SoC存储体系结构和实战
  • 原文地址:https://www.cnblogs.com/liujicai/p/6903394.html
Copyright © 2011-2022 走看看