CListCtrl OnItemchanged, loops 3 times??
-
Dear all, I am encountering a problem in calling this CListCtrl function, OnItemchanged. Whenever there is a change in selection, this functions will run 3 times!!! And, for the first time, the string got is " ", but at the second time, it shows the right string, then it is " " again for the third time. Can I know how does it happen for running 3 times? This is just a testing code. Actually I want to call another function whenever a selection is moved to another one, how can I do this if this function cannot work? void CTable::OnItemchangedtable(NMHDR* pNMHDR, LRESULT* pResult) { NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR; POSITION pos = m_table.GetFirstSelectedItemPosition(); int i = m_table.GetNextSelectedItem( pos ); CString cs = m_table.GetItemText(i, 0); AfxMessageBox( cs); *pResult = 0; } Thank you very much !!! Regards, Vickie
-
Dear all, I am encountering a problem in calling this CListCtrl function, OnItemchanged. Whenever there is a change in selection, this functions will run 3 times!!! And, for the first time, the string got is " ", but at the second time, it shows the right string, then it is " " again for the third time. Can I know how does it happen for running 3 times? This is just a testing code. Actually I want to call another function whenever a selection is moved to another one, how can I do this if this function cannot work? void CTable::OnItemchangedtable(NMHDR* pNMHDR, LRESULT* pResult) { NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR; POSITION pos = m_table.GetFirstSelectedItemPosition(); int i = m_table.GetNextSelectedItem( pos ); CString cs = m_table.GetItemText(i, 0); AfxMessageBox( cs); *pResult = 0; } Thank you very much !!! Regards, Vickie
why dont u use the NM_CLICK message instead? --- "every year we invent better idiot proof systems and every year they invent better idiots"
-
why dont u use the NM_CLICK message instead? --- "every year we invent better idiot proof systems and every year they invent better idiots"
-
Dear all, I am encountering a problem in calling this CListCtrl function, OnItemchanged. Whenever there is a change in selection, this functions will run 3 times!!! And, for the first time, the string got is " ", but at the second time, it shows the right string, then it is " " again for the third time. Can I know how does it happen for running 3 times? This is just a testing code. Actually I want to call another function whenever a selection is moved to another one, how can I do this if this function cannot work? void CTable::OnItemchangedtable(NMHDR* pNMHDR, LRESULT* pResult) { NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR; POSITION pos = m_table.GetFirstSelectedItemPosition(); int i = m_table.GetNextSelectedItem( pos ); CString cs = m_table.GetItemText(i, 0); AfxMessageBox( cs); *pResult = 0; } Thank you very much !!! Regards, Vickie
I can't remember why there are 3 calls, but the first is to indicate that an item state is changing, selection state is being removed and the third is to indicate that an item state is changing, selection state is being set. I'm guessing that the second call is to provide access to the string and possibly change it prior to it being selected. Check further and I think you will find that the item for the first call is not the same item as the item for the subsequent second and third call. Add the pNMListView pointer to the watch window and look at each of the member variables change for each of the three calls to the method. That might aid in your understanding of what is happening.
-
I can't remember why there are 3 calls, but the first is to indicate that an item state is changing, selection state is being removed and the third is to indicate that an item state is changing, selection state is being set. I'm guessing that the second call is to provide access to the string and possibly change it prior to it being selected. Check further and I think you will find that the item for the first call is not the same item as the item for the subsequent second and third call. Add the pNMListView pointer to the watch window and look at each of the member variables change for each of the three calls to the method. That might aid in your understanding of what is happening.
Thank you very much!! I got how to do it now. It is to check the status of pNMListView->uNewState and pNMListView->uOldState before operation as follow: void CTable::OnItemchangedtable(NMHDR* pNMHDR, LRESULT* pResult) { NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR; UINT u = pNMListView->uNewState; UINT n = pNMListView->uOldState; if( u != 0 && n == 0 ) { POSITION pos = m_table.GetFirstSelectedItemPosition(); int i = m_table.GetNextSelectedItem( pos ); CString cs = m_table.GetItemText(i, 0); AfxMessageBox( cs); } *pResult = 0; }