回复人: Adayuer([±0℃]) ( ) 信誉:96 2002-04-01 09:40:17Z 得分:0
看看我的一段代码吧。
用TTreeview实现的一个通讯录的组别设置,
联系人用Tlistview。
/---------------------------------------------------------------------------
void __fastcall TTBF::N5Click(TObject *Sender)
{
THitTests HT;
TTreeNode *Node1;
if (mouse_Sender&&mouse_Sender->ClassNameIs("TTreeView"))
{
TTreeView *pTV = (TTreeView *)mouse_Sender;
HT = pTV->GetHitTestInfoAt(mouse_x,mouse_y);
if (HT.Contains(htOnItem))
Node1=pTV->GetNodeAt(mouse_x,mouse_y);
if(Node1->Text=="全部")
{
MessageDlg("\\\"全部\\\"是系统组,不能删除!", mtWarning, TMsgDlgButtons() << mbYes, 0);
}
else
pTV->Items->Delete(Node1);
}
}
//---------------------------------------------------------------------------
void __fastcall TTBF::GroupTVMouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
mouse_x=X;
mouse_y=Y;
mouse_Sender=Sender;
}
//---------------------------------------------------------------------------
void __fastcall TTBF::N3Click(TObject *Sender)
{
THitTests HT;
TTreeNode *Node1;
if (mouse_Sender&&mouse_Sender->ClassNameIs("TTreeView"))
{
TTreeView *pTV = (TTreeView *)mouse_Sender;
HT = pTV->GetHitTestInfoAt(mouse_x,mouse_y);
if (HT.Contains(htOnItem))
{
Node1 = pTV->GetNodeAt(mouse_x,mouse_y);
if((Node1->Level==0)&&(Node1->Text=="全部"))
{
MessageDlg("\"全部\"是系统组,不能新建子键!", mtWarning, TMsgDlgButtons() << mbYes, 0);
return;
}
if(Node1->Level==1)
{
MessageDlg("只能建立两级组别!", mtWarning, TMsgDlgButtons() << mbYes, 0);
return;
}
else
{
TTreeNode *fNode;
String S="新组别";
fNode=Node1->getFirstChild();
if(fNode)
while(!NoSameName(fNode,S)){;};
pTV->Items->AddChild(Node1,S);
}
}
}
}
//---------------------------------------------------------------------------
void __fastcall TTBF::N2Click(TObject *Sender)
{
THitTests HT;
TTreeNode *Node1;
if (mouse_Sender&&mouse_Sender->ClassNameIs("TTreeView"))
{
TTreeView *pTV = (TTreeView *)mouse_Sender;
HT = pTV->GetHitTestInfoAt(mouse_x,mouse_y);
if (HT.Contains(htOnItem))
{
Node1 = pTV->GetNodeAt(mouse_x,mouse_y);
String S="新组别";
while(!NoSameName(Node1,S)){;};
pTV->Items->Add(Node1,S);
}
}
}
//---------------------------------------------------------------------------
void __fastcall TTBF::N4Click(TObject *Sender)
{
THitTests HT;
TTreeNode *Node1;
if (mouse_Sender&&mouse_Sender->ClassNameIs("TTreeView"))
{
TTreeView *pTV = (TTreeView *)mouse_Sender;
HT = pTV->GetHitTestInfoAt(mouse_x,mouse_y);
if (HT.Contains(htOnItem))
{
Node1=pTV->GetNodeAt(mouse_x,mouse_y);
if((Node1->Level==0)&&(Node1->Text=="全部"))
{
MessageDlg("\"全部\"是系统组,不能更名!", mtWarning, TMsgDlgButtons() << mbYes, 0);
}
else
Node1->EditText();
}
}
}
//---------------------------------------------------------------------------
void __fastcall TTBF::GroupTVClick(TObject *Sender)
{
/* THitTests HT;
TTreeNode *Node1;
if (Sender->ClassNameIs("TTreeView"))
{
TTreeView *pTV = (TTreeView *)Sender;
HT = pTV->GetHitTestInfoAt(mouse_x,mouse_y);
if (HT.Contains(htOnItem))
{
Node1 = pTV->GetNodeAt(mouse_x,mouse_y);
SB->SimpleText="AbsoluteIndex:"+IntToStr(Node1->AbsoluteIndex)+"\tIndex:"+IntToStr(Node1->Index)+"\tText["+Node1->Text+"]";
}
}
*/
}
//---------------------------------------------------------------------------
void __fastcall TTBF::GroupTVChange(TObject *Sender, TTreeNode *Node)
{
// SB->SimpleText="Count:"+IntToStr(Node->Count)+" AbsoluteIndex:"+IntToStr(Node->AbsoluteIndex)+" Index:"+IntToStr(Node->Index)+" Text["+Node->Text+"]";
TListItem *pItem;
String tmp;
TBLV->Items->Clear();
if((Node->Text=="全部"&&Node->Level==0))
{
for (int i = 0; i < M->tblist->Count; i++)
{
pItem = TBLV->Items->Add();
tmp=((TelItem*)(M->tblist->Items[i]))->name;
pItem->Caption = tmp;
pItem->SubItems->Add(String(((TelItem*)(M->tblist->Items[i]))->nick));
pItem->SubItems->Add(String(((TelItem*)(M->tblist->Items[i]))->phone));
pItem->SubItems->Add(String((((TelItem*)(M->tblist->Items[i]))->type==0)?"英文":"中文"));
pItem->SubItems->Add(String(((TelItem*)(M->tblist->Items[i]))->memo));
}
return;
}
else if(Node->Level==0)
{
for (int i = 0; i < M->tblist->Count; i++)
{
if(Node->Text!=String(((TelItem*)(M->tblist->Items[i]))->group))
continue;
pItem = TBLV->Items->Add();
tmp=((TelItem*)(M->tblist->Items[i]))->name;
pItem->Caption = tmp;
pItem->SubItems->Add(String(((TelItem*)(M->tblist->Items[i]))->nick));
pItem->SubItems->Add(String(((TelItem*)(M->tblist->Items[i]))->phone));
pItem->SubItems->Add(String((((TelItem*)(M->tblist->Items[i]))->type==0)?"英文":"中文"));
pItem->SubItems->Add(String(((TelItem*)(M->tblist->Items[i]))->memo));
}
return;
}
else if(Node->Level==1)
{
TTreeNode *pNode=Node->Parent;
for (int i = 0; i < M->tblist->Count; i++)
{
if((Node->Text!=String(((TelItem*)(M->tblist->Items[i]))->subgroup))||(pNode->Text!=String(((TelItem*)(M->tblist->Items[i]))->group)))
continue;
pItem = TBLV->Items->Add();
tmp=((TelItem*)(M->tblist->Items[i]))->name;
pItem->Caption = tmp;
pItem->SubItems->Add(String(((TelItem*)(M->tblist->Items[i]))->nick));
pItem->SubItems->Add(String(((TelItem*)(M->tblist->Items[i]))->phone));
pItem->SubItems->Add(String((((TelItem*)(M->tblist->Items[i]))->type==0)?"英文":"中文"));
pItem->SubItems->Add(String(((TelItem*)(M->tblist->Items[i]))->memo));
}
return;
}
}
//---------------------------------------------------------------------------
void __fastcall TTBF::GroupTVEditing(TObject *Sender, TTreeNode *Node,
bool &AllowEdit)
{
if((Node->Level==0)&&(Node->Text=="全部"))
AllowEdit=false;
else
oldtext=Node->Text;
}