Selecting Items  
Author Message
every_thing_freezes





PostPosted: Sat Jun 11 23:26:01 CDT 2005 Top

MFC >> Selecting Items

Hello,

I am puzzled on as to why I keep getting an empty string when I try to
select an item inserted in CTreeCtrl. I've constructed HTREEITEMS and
inserted them into CTreeCtrl. Then I am calling my OnTree(NMHDR* pNMHDR,
LRESULT* pResult) function that has these lines:

//1. Get tree view object.
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
//2. Construct a TVITEM
TVITEM an_item = (TVITEM)pNMTreeView->itemNew;
if (an_item.hItem != NULL)
{
MessageBox(m_tmain.GetItemText(an_item.hItem));
}
When I try to GetItemText, I get nothing. It is necessary for me to get
item text because I then pass this text string to ExpandItems function. Any
suggestion on how to capture text of selected items? Thank you very much in
advance.

Victor.

Visual Studio285  
 
 
victorsk





PostPosted: Sat Jun 11 23:26:01 CDT 2005 Top

MFC >> Selecting Items Hello,

Just a small addtion to my question. When I call
m_tmain.GetItemText(m_tmain.GetSelectedItem()) I am able to get the item
text, but the problems are:
1) To get item's text I have to click on it twice and when I select another
item I first get the name of previous item and then new item's name
2) I can only get item's text when I actually click on the item and not on +
sign beside it.

I was wondering if anyone else has encountered this problem and as I have
previously indicated my calls to get item text
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
TVITEM an_item = (TVITEM)pNMTreeView->itemNew;
are not working.
Please help,
Thank you,
Victor.



> Hello,
>
> I am puzzled on as to why I keep getting an empty string when I try to
> select an item inserted in CTreeCtrl. I've constructed HTREEITEMS and
> inserted them into CTreeCtrl. Then I am calling my OnTree(NMHDR* pNMHDR,
> LRESULT* pResult) function that has these lines:
>
> //1. Get tree view object.
> NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
> //2. Construct a TVITEM
> TVITEM an_item = (TVITEM)pNMTreeView->itemNew;
> if (an_item.hItem != NULL)
> {
> MessageBox(m_tmain.GetItemText(an_item.hItem));
> }
> When I try to GetItemText, I get nothing. It is necessary for me to get
> item text because I then pass this text string to ExpandItems function. Any
> suggestion on how to capture text of selected items? Thank you very much in
> advance.
>
> Victor.
 
 
Scott





PostPosted: Sun Jun 12 09:10:08 CDT 2005 Top

MFC >> Selecting Items
> Hello,
>
> Just a small addtion to my question. When I call
> m_tmain.GetItemText(m_tmain.GetSelectedItem()) I am able to get the item
> text, but the problems are:
> 1) To get item's text I have to click on it twice and when I select another
> item I first get the name of previous item and then new item's name
> 2) I can only get item's text when I actually click on the item and not on +
> sign beside it.
>
> I was wondering if anyone else has encountered this problem and as I have
> previously indicated my calls to get item text
> NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
> TVITEM an_item = (TVITEM)pNMTreeView->itemNew;
> are not working.
> Please help,
> Thank you,
> Victor.
>


That is quite an ugly line of code. Why did you put the (TMITEM) cast
in it? I'm not sure what the line will actually do. Have you examined
the members of an_item with the de**** to see what you are actually
getting?

But you don't appear to even need this ugly line! You can simply call
GetItemText on the pNMTreeView->itemNew.hItem that you already have.

--
Scott McPhillips [VC++ MVP]

 
 
victorsk





PostPosted: Sun Jun 12 10:18:03 CDT 2005 Top

MFC >> Selecting Items Hi,

Nope, sorry applying GetItemText on pNMTreeView->itemNew.hItem resulted in
nothing being shown when I put it in the MessageBox(). The value of
pNMTreeView->itemNew.hItem is non-null but why can't I see the actual text
string?

Victor.




> > Hello,
> >
> > Just a small addtion to my question. When I call
> > m_tmain.GetItemText(m_tmain.GetSelectedItem()) I am able to get the item
> > text, but the problems are:
> > 1) To get item's text I have to click on it twice and when I select another
> > item I first get the name of previous item and then new item's name
> > 2) I can only get item's text when I actually click on the item and not on +
> > sign beside it.
> >
> > I was wondering if anyone else has encountered this problem and as I have
> > previously indicated my calls to get item text
> > NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
> > TVITEM an_item = (TVITEM)pNMTreeView->itemNew;
> > are not working.
> > Please help,
> > Thank you,
> > Victor.
> >

>
> That is quite an ugly line of code. Why did you put the (TMITEM) cast
> in it? I'm not sure what the line will actually do. Have you examined
> the members of an_item with the de**** to see what you are actually
> getting?
>
> But you don't appear to even need this ugly line! You can simply call
> GetItemText on the pNMTreeView->itemNew.hItem that you already have.
>
> --
> Scott McPhillips [VC++ MVP]
>
>