Board index » cppbuilder » treeview question

treeview question


2003-08-26 05:41:47 PM
cppbuilder27
Hi,
i use next code:
void OpenReport(AnsiString MyString )
{
if(MyString == "MYITEM")
{
ShowMessage(" item found" );
}
}
void __fastcall TfrmReports::TreeView1Click(TObject *Sender)
{
TTreeNode *ATreeNode;
ATreeNode= TreeView1->Selected;
if (ATreeNode->Parent != 0 )
{
if (ATreeNode->Parent->Text == "Algemeen")
{
OpenReport(ATreeNode->Text, );
}
}
}
i have the next treeview
Algemeen
Mystring
Otherstring
Justonother string
hello
Mystring1
Mystring2
Mystring3
etc.etc.
the code work ok,
if i press Algemeen->MyString the messagebox is shown.
if i press onother string there is no messagebox.
but after i pressed Algemeen->MyString i click on the plus sign (+) from
another node,
this time the messagebox is shown to.
how can i solve this?
mvg
 
 

Re:treeview question

This code won't work the way you describe. It doesn't even
compile.
This line:
Quote
OpenReport(ATreeNode->Text, );
shouldn't have have a comma in it.
This line
Quote
if(MyString == "MYITEM")
prevents any of the node texts you show from causing
a message to display. Only a node with the text
"MYITEM" will display the message.
Quote
but after i pressed Algemeen->MyString i click on the plus sign (+) from
another node,
this time the messagebox is shown to.
Clicking the + sign doesn't change the selected node. You've
clicked the tree and the responsive node is still selected so
it responds.
Quote
how can i solve this?
Put your code into the OnChange event instead. This will cause
the message to display when you first select a responsive node.
The message won't display each time you click the node, if it's
already selected.
If you want that then you can leave your code in the OnClick event
and set a bool in the OnCollapsing and OnExpanding events to
inhibit display of the message.
The problem with this solution is that clicking anywhere in the
tree except on node text or a + or - sign causes the message to
display.
A better solution is to use the DisplayRect property of the responsive
nodes in conjunction with the MouseDown, MouseUp or MouseMove
events of the tree to determine whether you have hit, or are about to
hit, a responsive node.
Gerry.
 

Re:treeview question

"N. Karademir" < XXXX@XXXXX.COM >wrote in message
Quote
if i press onother string there is no messagebox.
but after i pressed Algemeen->MyString i click on the
plus sign (+) from another node,

this time the messagebox is shown to.
Clicking on an "+" does not change the currently selected item. You are
displaying a messagebox on every single click regardless of where that click
actually occurs, and then you are testing the current selected item, which
has not changed.
If you only want to display the message when the user clicks on an actual
item, you need to use the TreeView's GetHitTestInfoAt() method during the
click to retreive information about the location where the click is actually
occuring, and then act accordingly.
Gambit
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (www.grisoft.com).
Version: 6.0.512 / Virus Database: 309 - Release Date: 8/19/03
 

{smallsort}

Re:treeview question

Hi
I want to perform some action when I click on an item
on the treeview list, but only when the click was on a item
and not on "+/-" plus or minus signs
What method should i use?
Thanks Sorin
 

Re:treeview question

Sorin,
Use the OnMouseUp/OnMouseDown events on the TTreeView. In this event you are
passed a couple of parameters (X&Y) which you can put into a
TreeView.GetHitTestInfoAt(X,y) query.
If you get back a htOnLabel I think you may get what you are looking for
(take a peek at the online help for GetHitTestInfoAt.
Cheers
- Simon Moscrop
"Sorin Hershcu" < XXXX@XXXXX.COM >wrote in message
Quote
Hi
I want to perform some action when I click on an item
on the treeview list, but only when the click was on a item
and not on "+/-" plus or minus signs
What method should i use?
Thanks Sorin


 

Re:treeview question

Use the OnChange event of the TreeView as the Node you have clicked on is
passed to that event which you can setup like so:
procedure TForm1.TreeView1Change(Sender: TObject; Node: TTreeNode);
begin
if Node.Text = 'Text' then
begin
end;
{
or if each node has it's own image index do the following
}
case Node.ImageIndex of
0: ;
1: ;
2: ;
3: ;
4: ;
end;
end;
the event is only fired when changing a node (even when using a keyboard),
so you don't have to worry about checking the cursor position, etc.
 

Re:treeview question

Hi,
I set the MultiSelect Property of the TreeView to true and also set the
msControlSelect and msShiftSelect to true.
when I want to change the focused node programmatically, if the focused node
is one of the selected nodes, focus process not worked. And OnChange and
OnChanging methods do not call.
I used both these commands separately and together:
Tree->Selected = Tree->Items->Item[i];
Tree->Items->Item[i]->Focused = true;
What is my wrong? Any help would be appreciated.
Thank you,
Mehrdad
 

Re:treeview question

If an item is already selected, reselecting or refocusig it will not trigger
OnChange again.
That is normal because nothing changes at all. Thus you should manually
handle it.
for example:
if ( Tree->Selected != Tree->Items->Item[i] )
Tree->Selected = Tree->Items->Item[i]; // if the selection
changes, then just change it
else
call OnChange function manually here ( e.g OnTree1Change ( this,
... ); // else just call on change manully
----- Original Message -----
From: "M. Noroozi Eghbali" < XXXX@XXXXX.COM >
Newsgroups: borland.public.cppbuilder.vcl.components.using
Sent: Saturday, January 24, 2004 6:32 PM
Subject: TreeView question
Quote
Hi,

I set the MultiSelect Property of the TreeView to true and also set the
msControlSelect and msShiftSelect to true.

when I want to change the focused node programmatically, if the focused
node
is one of the selected nodes, focus process not worked. And OnChange and
OnChanging methods do not call.

I used both these commands separately and together:

Tree->Selected = Tree->Items->Item[i];
Tree->Items->Item[i]->Focused = true;

What is my wrong? Any help would be appreciated.

Thank you,
Mehrdad


 

Re:treeview question

Thank you for your answer. I did it, but still the new selected term not
focused.
Mehrdad
"Cagatay Undeger" < XXXX@XXXXX.COM >wrote in message
Quote
If an item is already selected, reselecting or refocusig it will not
trigger
OnChange again.
That is normal because nothing changes at all. Thus you should manually
handle it.

for example:

if ( Tree->Selected != Tree->Items->Item[i] )
Tree->Selected = Tree->Items->Item[i]; // if the selection
changes, then just change it
else
call OnChange function manually here ( e.g OnTree1Change (
this,
... ); // else just call on change manully

----- Original Message -----
From: "M. Noroozi Eghbali" < XXXX@XXXXX.COM >
Newsgroups: borland.public.cppbuilder.vcl.components.using
Sent: Saturday, January 24, 2004 6:32 PM
Subject: TreeView question


>Hi,
>
>I set the MultiSelect Property of the TreeView to true and also set the
>msControlSelect and msShiftSelect to true.
>
>when I want to change the focused node programmatically, if the focused
node
>is one of the selected nodes, focus process not worked. And OnChange and
>OnChanging methods do not call.
>
>I used both these commands separately and together:
>
>Tree->Selected = Tree->Items->Item[i];
>Tree->Items->Item[i]->Focused = true;
>
>What is my wrong? Any help would be appreciated.
>
>Thank you,
>Mehrdad
>
>


 

Re:treeview question

himm, I think I understand you wrong.
I didn't encounter a problem like that yet.
But what about deselecting first by assigning NULL, then selecting it again.
it may work.
"M. Noroozi Eghbali" < XXXX@XXXXX.COM >wrote in message
Quote
Thank you for your answer. I did it, but still the new selected term not
focused.

Mehrdad



"Cagatay Undeger" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...
>If an item is already selected, reselecting or refocusig it will not
trigger
>OnChange again.
>That is normal because nothing changes at all. Thus you should manually
>handle it.
>
>for example:
>
>if ( Tree->Selected != Tree->Items->Item[i] )
>Tree->Selected = Tree->Items->Item[i]; // if the
selection
>changes, then just change it
>else
>call OnChange function manually here ( e.g OnTree1Change (
this,
>... ); // else just call on change manully
>
>----- Original Message -----
>From: "M. Noroozi Eghbali" < XXXX@XXXXX.COM >
>Newsgroups: borland.public.cppbuilder.vcl.components.using
>Sent: Saturday, January 24, 2004 6:32 PM
>Subject: TreeView question
>
>
>>Hi,
>>
>>I set the MultiSelect Property of the TreeView to true and also set
the
>>msControlSelect and msShiftSelect to true.
>>
>>when I want to change the focused node programmatically, if the
focused
>node
>>is one of the selected nodes, focus process not worked. And OnChange
and
>>OnChanging methods do not call.
>>
>>I used both these commands separately and together:
>>
>>Tree->Selected = Tree->Items->Item[i];
>>Tree->Items->Item[i]->Focused = true;
>>
>>What is my wrong? Any help would be appreciated.
>>
>>Thank you,
>>Mehrdad
>>
>>
>
>


 

Re:treeview question

Hi,
I have a TTreeView with static nodes and sub-nodes, and I am trying to find
a way to know which node/ sub-node exactly selected under TreeView OnChange
event. Taking in consideration that some of the sub-nodes have the same
text.
So can someone help me please and tell me how I can do so?
Thanks in advance for your time and efforts.
Best Regards
 

Re:treeview question

On Thu, 8 Sep 2005 06:59:01 -0700, PeterS wrote:
Quote
am trying to find
a way to know which node/ sub-node exactly selected under TreeView OnChange
event
What exactly do you want to do? Why do you need the specific one?
--
liz
 

Re:treeview question

"PeterS" < XXXX@XXXXX.COM >wrote in message
Quote
I have a TTreeView with static nodes and sub-nodes, and I am trying
to find a way to know which node/ sub-node exactly selected under
TreeView OnChange event.
The event handler has a Node parameter which is a pointer to the Node that
is changing.
Gambit