Re: Detect changes in ClistCtrl control with checkbox
Thanks Ian. I did it this way and it works fine for me-
I just wanted to confirm, since I am using constant 0x2000 and 0x1000 here,
can I be sure that these checks will not be bricked in some other environment
like other version of windows OS or Visual Studio?
int oldState = -1;
int newState = -1;
int changedState= -1;
int ns1 = pNMLV->uOldState & LVIS_STATEIMAGEMASK;
int ns2 = pNMLV->uNewState & LVIS_STATEIMAGEMASK;
if ((ns1 & 0x2000) != 0)// find the previous state
{ //Checkbox set
oldState = 1;
}
else if ((ns1 & 0x1000) != 0)
{
//Checkbox unset
oldState = 0;
}
if (-1 != oldState)// If got the previous state then find the new state
{
if ((ns2 & 0x2000) != 0)
{ //Checkbox set
newState = 1;
}
else if ((ns2 & 0x1000) != 0 )
{
//Checkbox unset
newState = 0;
}
if ( (-1 != newState) && (oldState != newState))
{
changedState = newState - oldState;
if (1 == changedState)
{
AfxMessageBox(_T("Item has been checked"));
}
else if (-1 == changedState)
{
AfxMessageBox(_T("Item has been unchecked"));
}
}
}
"Ian Semmel" wrote:
In the LVN_ITEMCHANGED handler you can put
int ns = pNMListView ->uNewState & LVIS_STATEIMAGEMASK;
if ( ( ns & 0x2000 ) != 0 )
// Checkbox set
else if ( ( ns & 0x1000 ) != 0 )
// Checkbox unset
else
// Something else happened
asoni12 wrote:
"Ajay Kalra" wrote:
On Jan 13, 11:31 am, asoni12 <ason...@discussions.microsoft.com>
wrote:
I am using a CListCtrl with LVS_EX_CHECKBOXES extended style. How can I
detect that a previously checked item has been unchecked or a previously
unchecked item has been checked. I know that LVN_ITEMCHANGED event is
triggered whenever its state gets changed but how to find if the item has
been checked / unchecked and its previously state.
Any help is appreciated.
Take a look at ListView_GetCheckState: http://msdn.microsoft.com/en-us/library/bb761250(VS.85).aspx
and LVN_ITEMCHANGING: http://msdn.microsoft.com/en-us/library/bb774847(VS.85).aspx
--
Ajay
Hi Ajay,
Thanks for the quick reply.
We get a pointer to an NMLISTVIEW structure in case of both both
LVN_ITEMCHANGING and LVN_ITEMCHANGED event handlers but with this structure
how can we make sure whether items???s checked/unchecked state has been
toggled or something else has changed?
I mean is there any bit in this structure member which is set/unset when the
state gets toggled?