Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

TVN_SELCHANGED and TVN_SELCHANGING for a CTreeCtrl

538 views
Skip to first unread message

Adam Christensen

unread,
Jan 17, 1997, 3:00:00 AM1/17/97
to

I am handling the TVN_SELCHANGING message for a tree contol
in order to do some data validation before the selection actually
changes. (My validation cannot be done with a simple DDV call.)
I then handle the TVN_SELCHANGED message so that I can
put new data in some edit controls, depending on which tree item
is selected.

My question is:
If the data that I test when I handle the TVN_SELCHANGING
message is not valid, how can I stop the TVN_SELCHANGED
from happening (make the tree item with the bad data stay
as the selected item), and set the focus to the control with bad
data?

Thanks in advance,

Adam Christensen

Justin Rudd

unread,
Jan 18, 1997, 3:00:00 AM1/18/97
to

Well I tried stopping it...I had no success...I overloaded
PreTranslateMessage and OnNotify. I could intercept it in both...but
when I would return TRUE to say I handle it...well...the selection
would go through anyway. So here is what I did...

void CTreeDlg::OnSelChangingTree(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;

HTREEITEM hItemOld = pNMTreeView->itemOld.hItem;
if( hItemOld )
{
if( m_tree.GetItemData( hItemOld ) == 1010 )
m_fInvalidItem = TRUE;
else
m_fInvalidItem = FALSE;
}

*pResult = 0;
}

void CTreeDlg::OnSelchangedTree(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;

if( m_fInvalidItem )
{
m_tree.SelectItem( pNMTreeView->itemOld.hItem );
*pResult = 0;
return;
}

if( pNMTreeView->itemNew.hItem )
{
m_lDisplay = m_tree.GetItemData(
pNMTreeView->itemNew.hItem );
UpdateData(FALSE);
}

*pResult = 0;
}


This is a simple basic dialog I threw together to see if I could stop
that message. The above works, but it has a horrible side effect.
Lets say I have the 3rd item selected...I change the data member to be
1010 like I check for above. I then move to another...it finds out
that the 3rd Item is invalid so it sets m_fInvalidItem to TRUE. So
here is what the tree control does...draw the selection around the
OTHER item I selected and then instantly switches it back to the 3rd
Item. Not exactly a nice thing...but it doesn't let them come off the
3rd until they fix the data.

Sorry I couldn't help more...

Justin

Remove .---- from address to mail...
Spam has just gotten too bad.

Aditi Corporation

unread,
Jan 20, 1997, 3:00:00 AM1/20/97
to

Hi Adam,


>>>>
My question is:
If the data that I test when I handle the TVN_SELCHANGING
message is not valid, how can I stop the TVN_SELCHANGED
from happening (make the tree item with the bad data stay
as the selected item), and set the focus to the control with bad
data?
>>>>

You can stop the TVN_SELCHANGED event being triggered, by assigning TRUE to
the second parameter of your TVN_SELCHANGING event's procedure.
It's a LRESULT value.

Aditi Corp was formerly known as NetQuest Inc.

P.S. : Worried about response times to your queries?
Check out our FREE technical support service at http://www.aditi.com/nntp.htm
OR just click on the attached link

begin 600 link.url
M6TEN=&5R;F5T4VAO<G1C=71=#0I54DP]:'1T<#HO+W=W=RYA9&ET:2YC;VTO
*;FYT<"YH=&T-"FAO
`
End


0 new messages