Board index » delphi » TreeView - making sure that OnEdited always gets fired

TreeView - making sure that OnEdited always gets fired

I wrote code to rename node on TTreeView control. The user is clicking
appropriate menu item, and following code is executed:

oSelNode.Text := oSelNode.Text + ' ' + sAppendedText;

// Start edit mode for selected node.
oSelNode.EditText;

Everything works fine: appropriate string is appended to the caption of the
node, and node goes into edit mode, in case if the user wants to adjust new
caption.

So far so good. But: at the end of the editing (for example, when the user
clicks another control on the form and TTreeView loses focus), event
OnEdited is not firing! When the edit mode is entered "normally" (i.e. user
clicks the selected node), at the end of the editing event OnEdited is
always firing.

It is important for me because in OnEdited event I have critical code for
renaming the node - it checks for duplicate names in the tree etc. When this
code is not executed, data maintained by my program gets corrupted.

So, my question is: is there any way to make sure that OnEdited always
happens? I tried to find some API calls, to send some messages to the tree
etc, but nothing works.

Thank you in advance,

Darek Dziewialtowski.

 

Re:TreeView - making sure that OnEdited always gets fired


Quote
"Dariusz Dziewialtowski" <da...@netrover.com> wrote in message

news:cLqS6.244105$Z2.2766979@nnrp1.uunet.ca...

Quote
> I wrote code to rename node on TTreeView control. The user is clicking
> appropriate menu item, and following code is executed:

> oSelNode.Text := oSelNode.Text + ' ' + sAppendedText;

> // Start edit mode for selected node.
> oSelNode.EditText;

> Everything works fine: appropriate string is appended to the caption of
the
> node, and node goes into edit mode, in case if the user wants to adjust
new
> caption.

> So far so good. But: at the end of the editing (for example, when the user
> clicks another control on the form and TTreeView loses focus), event
> OnEdited is not firing! When the edit mode is entered "normally" (i.e.
user
> clicks the selected node), at the end of the editing event OnEdited is
> always firing.

> It is important for me because in OnEdited event I have critical code for
> renaming the node - it checks for duplicate names in the tree etc. When
this
> code is not executed, data maintained by my program gets corrupted.

> So, my question is: is there any way to make sure that OnEdited always
> happens? I tried to find some API calls, to send some messages to the tree
> etc, but nothing works.

> Thank you in advance,

> Darek Dziewialtowski.

Maybe if you get OnDeactivate to fire onEdited?

Regards Andrew O
http://www.freesoft.fsnet.co.uk

Re:TreeView - making sure that OnEdited always gets fired


Quote
> Maybe if you get OnDeactivate to fire onEdited?

Thanks, but I couldn't make it work.

Finally I managed to get desired results by putting following line in the
routine which is renaming the node:

    // Trigger Edited event in order to call validation and saving routines.
    tvwTreeEdited(Sender,oSelNode,sNewCaption);

That works fine.

Re:TreeView - making sure that OnEdited always gets fired


In article <cLqS6.244105$Z2.2766...@nnrp1.uunet.ca>, "Dariusz Dziewialtowski"

Quote
<da...@netrover.com> writes:
>So far so good. But: at the end of the editing (for example, when the user
>clicks another control on the form and TTreeView loses focus), event
>OnEdited is not firing! When the edit mode is entered "normally" (i.e. user
>clicks the selected node), at the end of the editing event OnEdited is
>always firing.

Although its after you have found the solution - here's why it doesn't work
<g>.

TTreenode.EditText just calls the win API TreeView_EditLabel(), of which MSDN
says ...

"The control must have the focus before you call this macro. Focus can be set
using the SetFocus function."

Alan Lloyd
alangll...@aol.com

Re:TreeView - making sure that OnEdited always gets fired


Quote
> Although its after you have found the solution - here's why it doesn't
work
> <g>.

> TTreenode.EditText just calls the win API TreeView_EditLabel(), of which
MSDN
> says ...

> "The control must have the focus before you call this macro. Focus can be
set
> using the SetFocus function."

Thanks a lot - that helps to understand what's going on behind the scenes.

Now, I have another question, for which you might know the answer:

when the TTreeView node is in Edit state, in fact some Edit control has
focus - when we type in some text, in fact that text is entered into Edit
control, not the "node" control (well, I know that there is no such thing as
"node" control).

My question is: how to get handle to that Edit control?

I need that because I'd like to read the text entered by the user at the
time when the user enters that text (reading at the EndEdit event it to late
for me). Once I got the handle to that control, I could send some messages
to it to query it for contained text.

TIA

Dariusz Dziewialtowski.

Re:TreeView - making sure that OnEdited always gets fired


Quote
"Dariusz Dziewialtowski" <da...@netrover.com> wrote in message

news:ly8T6.244918

Quote
> My question is: how to get handle to that Edit control?

I don't think you need it. Use one of the OnKey events and check for
IsEditing in the event.

Re:TreeView - making sure that OnEdited always gets fired


In article <ly8T6.244918$Z2.2790...@nnrp1.uunet.ca>, "Dariusz Dziewialtowski"

Quote
<da...@netrover.com> writes:
>My question is: how to get handle to that Edit control?

The handle of the edit control is a private variable of TCustomEdit, and so you
cannot get it without doing some really serious hacking <g>.

Alan Lloyd
alangll...@aol.com

Re:TreeView - making sure that OnEdited always gets fired


Quote
>I don't think you need it. Use one of the OnKey events and check for
>IsEditing in the event.
>The handle of the edit control is a private variable of TCustomEdit, and so
you
>cannot get it without doing some really serious hacking <g>.

Thank you Bruce and Alan for your help. Sounds like strong discouragement
for playing with this CustomEdit thing!

If that's how the things look like, I can live without this. I am surprised,
because I was doing similar things in VB and they were not so tough, and
they worked (when the cell on the grid is edited, in fact some floating Edit
control is being edited; I was getting its handle by calling something like
ActiveControl.hWnd - don't remember exact syntax, and then was sending some
messages to it; well, may be I had to much time :) )

Again, I will follow your advice - thanks for it - probably it saved me lot
of time!

Dariusz Dziewialtowski.

Other Threads