If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Press space key in CListCtrl object

Hi,

I'm writing an app using CListCtrl. Each row got a check box at the front. The requirement is user can use keyboard to check/uncheck the items in the list.

Now I have a problem with following scenario:
1. User click Tab to move focus onto the list
2. Press space, the checkbox is NOT updated
3. Press up or down key for the first time, nothing happens
4. Press up or down key once again, the cursor (selected row) will move up/down accordingly
5. At this time, press space again, the checkbox will be updated

Re: Press space key in CListCtrl object

Originally Posted by wangee

... Each row got a check box at the front. The requirement is user can use keyboard to check/uncheck the items in the list.
...
Does anyone knows why space key cannot work until press navigation key twice?

Do you handle "press space key" yourself or there is some ListCtrl internal functionality?

Re: Press space key in CListCtrl object

Originally Posted by wangee

No. I don't have any modified OnKeyDown event control.

Well, I presume you answered the first part of my question, not the second!
I have just tested a similar control in one of my projects... It does work as expected: checkbox state of the item that has a focus (LVIS_FOCUSED state) changes after each space key press.

Re: Press space key in CListCtrl object

Originally Posted by VictorN

Well, I presume you answered the first part of my question, not the second!
I have just tested a similar control in one of my projects... It does work as expected: checkbox state of the item that has a focus (LVIS_FOCUSED state) changes after each space key press.

Thanks Victor.

To your 2nd part of ur question, I think there's an internal functionaly that changes checkbox when space key pressed. Actually I use CMFCListCtrl class in my project.

I'm very interested your way to control the state of the checkbox? I tried "SetCheck" function, but it not always works. Do you mean you use "SetCheck" together with "SetItemState(i,LVIS_FOCUSED,LVIS_FOCUSED)"?

Re: Press space key in CListCtrl object

Originally Posted by wangee

To your 2nd part of ur question, I think there's an internal functionaly that changes checkbox when space key pressed. Actually I use CMFCListCtrl class in my project.

OK, good! I also use the " internal functionality that changes checkbox" when I press space key.
As for the CMFCListCtrl class - I never used it and have no idea whether something was changed in checkbox behaviour.

Originally Posted by wangee

I tried "SetCheck" function, but it not always works. Do you mean you use "SetCheck" together with "SetItemState(i,LVIS_FOCUSED,LVIS_FOCUSED)"?

1. Define "not always works".

2. No I didn't mean "I use "SetCheck" together with "SetItemState" nor used I SetItemState to change checkbox state.
However, when I need to check/uncheck an item from my code I do use SetCheck.