Solved

Selected TreeView??

Posted on 1998-04-01
7
1,258 Views
Last Modified: 2008-02-01
I am using Borland C++ Builder v3.0 Standard edition and I tried the following codes to see what the current TreeView node is selected.

if (TreeView1->Selected == "Business Operation Agreements") {
 RichEdit1->Text = "yes";
 }
else {
 RichEdit1->Text = "no";
}

But it didn't work.  My RichEdit1 just said no.

any reasons??
0
Comment
Question by:highvoltagerd
  • 3
  • 3
7 Comments
 
LVL 4

Expert Comment

by:jtwine100697
ID: 1184005
  Hmmm...  I do not know Borland OWL stuff, but are you sure that the "Selected" variable (function?) contains/returns the text of the selected item, not the HTREEITEM of the node selected?

-=- James.
0
 

Author Comment

by:highvoltagerd
ID: 1184006
Yip it is the correct function..  That is what the help files says.  But help is not to helpful!
0
 
LVL 4

Expert Comment

by:jtwine100697
ID: 1184007
  What do your help files read as far as return values from the "Selected" function or variable.

-=- James.
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

Author Comment

by:highvoltagerd
ID: 1184008
Specifies the selected node in the tree view.

__property TTreeNode* Selected = {read=GetSelection, write=SetSelection};

Description

Read Selected to access the selected node of the tree view. If there is no selected node, the value of Selected is NULL.

Set Selected to set a node in the tree view. When a node becomes selected, the tree view's OnChanging and OnChanged events occur. Also, if the specified node is the child of a collapsed parent item, the parent's list of child items is expanded to reveal the specified node. In this case, the tree views OnExpanded and OnExpanding events occur as well.

Note:      If the RightClickSelect property is true, the value of Selected is the last node that was clicked in the tree view, even if it was clicked with the right mouse button.  This may differ from the node that is highlighted to indicate selection.

The following code deletes the selected item in the tree view.

TreeView1->Selected->Delete();

The following code uses GetNodeAt to add a dragged node as a child of the node under then mouse when it is dropped.

void __fastcall TForm1::TreeView1DragDrop(TObject *Sender, TObject *Source, int X, int Y)

{
  if (Source != (TObject *)TreeView1 || TreeView1->Selected == NULL)
    return;
  THitTests HT = TreeView1->GetHitTestInfoAt(X, Y);
  TNodeAttachMode AttachMode;
  TTreeNode *pItem = TreeView1->GetNodeAt(X, Y);
  if (HT.Contains(htOnItem) || HT.Contains(htOnIcon))
    AttachMode = naAddChild;
  else if (HT.Contains(htNowhere))
    AttachMode = naAdd;
  else if (HT.Contains(htOnIndent))

    AttachMode = naInsert;
  else
    return;
  TreeView1->Selected->MoveTo(pItem, AttachMode);
}
0
 
LVL 4

Expert Comment

by:jtwine100697
ID: 1184009
  Just as I thought, it returns pointer to a "TTreeNode" (whatever that is..).  I would think that when you insert items into the Tree, you would get a "TTreeNode" pointer to reference it by.

   You need to figure out how to get the text of the selected item from the "TTreeNode" pointer returned by "Selected" (be sure to check for NULL first!).  Once you have the text, you can compare it with your search key.

  PS: Ever got the rich edit thing working...? :P

-=- James.
0
 

Author Comment

by:highvoltagerd
ID: 1184010
I looked and can only find index numbers to link to graphics (to display the graphic next to the node).
0
 
LVL 3

Accepted Solution

by:
q2guo earned 50 total points
ID: 1184011
if ((TreeView1->Selected)->Text== "Business Operation Agreements") {
     RichEdit1->Text = "yes";
}
else {
     RichEdit1->Text = "no";
}
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question