Print this
window
void TfrmTreeView::displayTreeNode(long MAXSIZE)
{
if (MAXSIZE)
{
SendMessage(tvTreeView->Handle, WM_SETREDRAW, 0, 0); // Turn off the redrawing
TTreeNode *nodeName;
nodeName = tvTreeView->Items->Add(NULL, Driver->getFile(0)); // Creating the main parent of TreeNode
long i = 1;
while ((ibDidCancelSearch)) // While there are still files to list and the user did not cancel the listing of the tree view
{
if (!strstr(Driver->getFile(i), "Sub Total = ")) // Don't place in the sub total into the file list
{
if (!FileExists(Driver->getFile(i))) // This is a directory, when need to find its parent to drop it into the correct place into the tree
nodeName = tvTreeView->Items->AddChild(getNodeHandle( // Pass in the directory that we are wanting to place into the node
Driver->getFile(i)), Driver->getFile(i));
else
tvTreeView->Items->AddChild(nodeName, ExtractFileName(Driver->getFile(i)));// This is a file so just add it to the current node
Application->ProcessMessages(); // See if the user is trying to do some thing with the program
} // End the if
i++;
} // End the for
SendMessage(tvTreeView->Handle, WM_SETREDRAW, 1, 0); // Now redraw the control
tvTreeView->FullExpand(); // Expand the tree so that the user can see it
} // End the if
} // End the displayTreeNode method
//=============================================================================
TTreeNode *TfrmTreeView::getNodeHandle(AnsiString dir)
{
int i;
TTreeNode *currNode; // Declare the node
TTreeNode *setNode = NULL; // Declare the one that you are going after, but set it to null incase you do not find it
for (i=(dir.Length() - 2);i>0;i--) // Have to back it up two because of the slash and the NULL on the end.
{
if (dir[i] == '\\') // Found the previous directory
{
dir.SetLength(i); // Set the length to get only that piece of it and the break out of the loop
break;
} // End the if
} // End the for
for (int tvIndex=(tvTreeView->Items->Count-1);tvIndex>0;tvIndex--)
{
currNode = tvTreeView->Items->Item[tvIndex]; // What is the caption in the current Node that we are looking at
if (dir == currNode->Text) // If it matches the diretory that we trying to link into the node then it is its parent
{
setNode = currNode; // Pass that node handle back so that we can link it in
break; // Break out of the loop, we are done looking
} // End the if
} // End the for
return setNode; // Return the node so that we know which one to link it into
} // End the getNodeHandle method