如何实现树形控件可编辑状态
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何实现树形控件可编辑状态相关的知识,希望对你有一定的参考价值。
参考技术A 如果是WPF实现:在XAML中,TreeViewItem里包含一个TextBlock,当双击时替换为TextBox,或两个都放按需隐藏一个显示另一个,或直接将TextBox放在TreeViewItem内部。
修改途中点击其他地方响应TreeViewItem.OnLostFocus即可。
树形控件数据刷新前,保存及还原展开和选中状态
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();
}
}
以上是关于如何实现树形控件可编辑状态的主要内容,如果未能解决你的问题,请参考以下文章