|
김성국 님이 쓰신 글 :
: 탐색기 처럼 옆에 트리에서 선택한 내용이 리스트뷰에서 그대로
: 해당트리내용이 뜨게 하려고 하거든요..
:
: 먼저 node를 생성할때...
:
: TreeView1->Items->Add(Node1,"안씨스트링");
: 이렇게 생성하잔아요...
:
: 근데..listview에서는 탐색기 처럼 생성날짜, 이름, 파일크기, 소유자
: 이런 컬럼등을 나타내야 하는데..
: 노드자체 생성시 안씨 스트링으로 넣어서 노드를 생성시키면
: 생성날짜 파일크기, 소유자등을 어떻게 나타내게 할수 있을까요?
: 원래는 클래스 객체를 만들어서 생성시키고 그것을 넘길려고 햇는데..
: 방법이 보이지 않는군요...검색해도 이 내용은 보이지 않고...
:
: 간단한 예제소스가지고 계신분이나..경험이 잇으신분 부탁드립니다..
:
: 그럼 즐푸~~~
:
:
:
요렇게
=================================================
Adds a new node containing data to a tree view.
=================================================
TTreeNode* __fastcall AddObject(TTreeNode* Node, const System::AnsiString S, void * Ptr);
Description
The node is added as the last sibling of the node specified by the Node parameter.
The S parameter specifies the Text property of the new node.
The Ptr parameter specifies the Data property value of the new node. AddObject returns the node that has been added.
Note: The memory referenced by Ptr is not freed when the tree nodes object is freed.
The following code defines a record type of TMyRec and a record pointer type of PMyRec.
typedef struct MyRec
{
AnsiString FName, LName;
} TMyRec;
typedef TMyRec* PMyRec;
Assuming these types are used, the following code adds a node to TreeView1 as the last sibling of a specified node. A TMyRec record is associated with the added item. The FName and LName fields are obtained from edit boxes Edit1 and Edit2. The Index parameter is obtained from edit box Edit3. The item is added only if the Index is a valid value.
void __fastcall TForm1::Button1Click(TObject *Sender)
{
PMyRec MyRecPtr;
int TreeViewIndex;
TTreeNodes* pItems;
MyRecPtr = new TMyRec;
MyRecPtr->FName = Edit1->Text;
MyRecPtr->LName = Edit2->Text;
TreeViewIndex = StrToInt(Edit3->Text);
pItems = TreeView1->Items;
if (pItems->Count == 0)
pItems->AddObject(NULL, "Item" + IntToStr(TreeViewIndex), MyRecPtr);
else if ((TreeViewIndex < pItems->Count) && (TreeViewIndex >= 0))
pItems->AddObject(pItems->Item[TreeViewIndex], "Item" + IntToStr(TreeViewIndex), MyRecPtr);
}
After an item containing a TMyRec record has been added, the following code retrieves the FName and LName values associated with the item and displays the values in a label.
void __fastcall TForm1::Button2Click(TObject *Sender)
{
Label1->Caption = PMyRec(TreeView1->Selected->Data)->FName + " " +
PMyRec(TreeView1->Selected->Data)->LName;
}
|