Board index » cppbuilder » OnEditing / OnEdited in a TListView

OnEditing / OnEdited in a TListView

If you click on the caption of an item displayed in a TListView, then
an OnEditing event is generated, if you then press return without
actually changing the caption, the OnEdited event is NOT generated.
It appears that the OnEdited event is only generated when the caption
is actually altered. In my case I need to be notified that the edit
has finished whether the caption has changed or not. Does anyone know
how this may be done ?

TIA

Rick

 

Re:OnEditing / OnEdited in a TListView


Hi Rick,

Quote
> If you click on the caption of an item displayed in a TListView, then
> an OnEditing event is generated, if you then press return without
> actually changing the caption, the OnEdited event is NOT generated.
> It appears that the OnEdited event is only generated when the caption
> is actually altered. In my case I need to be notified that the edit
> has finished whether the caption has changed or not. Does anyone know
> how this may be done ?

When the user has finished editing the caption of a ListView's item,
Windows sends the Parent of the ListView the WM_NOTIFY message with an
LVN_ENDLABELEDIT notification.  This notification messsage is sent
regardless of whether or not the caption was changed.  To get this
notification, handle the WM_NOTIFY message at the level of the
ListView's Parent.  For example, if the ListView is parented to your
Form, use a technique similar to the following...

// in header...
    void __fastcall WMNotify(TMessage &Msg);

BEGIN_MESSAGE_MAP
    MESSAGE_HANDLER(WM_NOTIFY, TMessage, WMNotify)
END_MESSAGE_MAP(TForm)

// in source...
void __fastcall TForm1::WMNotify(TMessage &Msg)
{
    LPNMHDR lpnmh = reinterpret_cast<LPNMHDR>(Msg.LParam);
    if (lpnmh->hwndFrom == ListView1->Handle &&
        lpnmh->code == LVN_ENDLABELEDIT)
    {
        // end caption editing
    }
    TForm::Dispatch(&Msg);

Quote
}

Alternatively, you can create a new TListView descendant and handle the
CN_NOTIFY (reflected) VCL message in the descendant's implementation.

HTH.

Damon C.

Other Threads