List control events
-
All, History: I have a list control that I used the onclick event to perform action with. The user wanted to be able to use the up/down arrows so I changed the event handler to use the itemchanged message. Now: The user wants to use both the mouse and the arrows - which is fine since the itemchanged message takes care of both of these actions. The problem being that the user also wants to be able to reperform (if that's a word) the same actions (it's a function to do a lot of number crunching on some data) on the currently selected item. The problem is that the itemchanged message gets called 3 times and thus the number crunching takes place 3 times! How do I get this to handle both mouse clicks and up/down arrows without having my function called 3 times? Thanks in advance, John
-
All, History: I have a list control that I used the onclick event to perform action with. The user wanted to be able to use the up/down arrows so I changed the event handler to use the itemchanged message. Now: The user wants to use both the mouse and the arrows - which is fine since the itemchanged message takes care of both of these actions. The problem being that the user also wants to be able to reperform (if that's a word) the same actions (it's a function to do a lot of number crunching on some data) on the currently selected item. The problem is that the itemchanged message gets called 3 times and thus the number crunching takes place 3 times! How do I get this to handle both mouse clicks and up/down arrows without having my function called 3 times? Thanks in advance, John
the function is called three times for the selected and the item that is being unselected(if thats a word :) ) so i am going by memory here it is called once when the previously selected item is Unselected, then for the new item that is selected and the the newly selected item gains focus rect examin the NM_LISTVIEW structure that is passed it contains the ItemNo and the Reason(selected, unselected etc) and then perform ur action Hope it helps :) C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg
-
All, History: I have a list control that I used the onclick event to perform action with. The user wanted to be able to use the up/down arrows so I changed the event handler to use the itemchanged message. Now: The user wants to use both the mouse and the arrows - which is fine since the itemchanged message takes care of both of these actions. The problem being that the user also wants to be able to reperform (if that's a word) the same actions (it's a function to do a lot of number crunching on some data) on the currently selected item. The problem is that the itemchanged message gets called 3 times and thus the number crunching takes place 3 times! How do I get this to handle both mouse clicks and up/down arrows without having my function called 3 times? Thanks in advance, John
-
Like this (I think) void CYourDialog::OnClickList2(NMHDR* pNMHDR, LRESULT* pResult) { LPNMLISTVIEW pnmv = (LPNMLISTVIEW) pNMHDR; if(pnmv->uNewState & LVIS_SELECTED) { // do long running stuff } }
Thanks - that almost works... It fails when I want to click on an already selected item and process data. (I'm varying some algorithm params in the dialog and observing the effect). So, I guess all I really want to do is to be able to use the up/down arrows to scroll and automatically process AND be able to use the mouse click to randomally select list data as well as process an already selected item. Is this the correct approach (using these events or do I need to set and clear some global bool that I create to bypass all these cascading events?) Thanks, John
-
Thanks - that almost works... It fails when I want to click on an already selected item and process data. (I'm varying some algorithm params in the dialog and observing the effect). So, I guess all I really want to do is to be able to use the up/down arrows to scroll and automatically process AND be able to use the mouse click to randomally select list data as well as process an already selected item. Is this the correct approach (using these events or do I need to set and clear some global bool that I create to bypass all these cascading events?) Thanks, John