CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jul 2008
    Posts
    9

    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

    Does anyone knows why space key cannot work until press navigation key twice?

    Thanks a lot!

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Press space key in CListCtrl object

    Quote Originally Posted by wangee View Post
    ... 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?
    Victor Nijegorodov

  3. #3
    Join Date
    Jul 2008
    Posts
    9

    Re: Press space key in CListCtrl object

    Quote Originally Posted by VictorN View Post
    Do you handle "press space key" yourself or there is some ListCtrl internal functionality?
    No. I don't have any modified OnKeyDown event control.

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Press space key in CListCtrl object

    Quote Originally Posted by wangee View Post
    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.
    Victor Nijegorodov

  5. #5
    Join Date
    Jul 2008
    Posts
    9

    Re: Press space key in CListCtrl object

    Quote Originally Posted by VictorN View Post
    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)"?

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Press space key in CListCtrl object

    Quote Originally Posted by wangee View Post
    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.

    Quote Originally Posted by wangee View Post
    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.
    Victor Nijegorodov

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured