Thread: Selected Items in a ListView

  1. #1
    Lowas
    Guest

    Selected Items in a ListView

    I can select items in a ListView with a click or with the arrow keys using CListCtrl but I want the first item to be selected when the prog loads ....how do I accomlish this? I've tried SetFocus() and other functions but I have not gotten it to work.

    Any ideas?

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    15

    Lowas

    Bump!
    Does anyone have any idea?

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    15

    Lowas

    Ok, I have the item selected as I wanted and now only the blue color is missing ....talking to myself here =P

  4. #4
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    try using CListCtrl::SetHotItem()
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  5. #5
    Registered User
    Join Date
    Aug 2001
    Posts
    15

    Smile Lowas

    Thx, I haven't tried that one, I'll check it out.

  6. #6
    Registered User
    Join Date
    Aug 2001
    Posts
    15

    Lowas

    SetHotItem() turns the text blue, what I'm really looking for is the blue rectangle u get when you use the arrow keys or u click on a item, this is what happens in explorer for instance.

    But I want it straight away without clicking or pressing a key =P.

    Anyway, it may be that I have to "paint" the area after Ive made the call to SetItemState()

    thx anyway

  7. #7
    Registered User
    Join Date
    Aug 2001
    Posts
    15

    Lowas

    Why didn't they just write a SetSelectedItem() function?

  8. #8
    Registered User
    Join Date
    Aug 2001
    Posts
    15

    Lowas

    The SetHotItem() will become useful for other things so thx again

  9. #9
    Registered User Esss's Avatar
    Join Date
    Aug 2001
    Posts
    133
    Use CListCtrl::SetItemState, passing LVIS_SELECTED for both state and mask.
    Ess
    Like a rat in a maze who says,
    "Watch me choose my own direction"
    Are you under the illusion
    The path is winding your way?
    - Rush

  10. #10
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,227
    Drats, Esss! You beat me to it!

    actually, I was gonna give him an API way (God forbid someone ever use the actual API... ), then I realized that he was using MFC so I had to edit the post...so...wahoo!

  11. #11
    Registered User
    Join Date
    Aug 2001
    Posts
    15

    Lowas

    Thx, perfect.

    I was using LVIS_SELECTED only for the mask, now when I initialize state with it also everything works just like I wanted.

    to KEN:
    I don't use MFC in particular, it's all WIN32 API anyway.
    It depends on the program I want to make, if I make games I use straight WIN32API but if I do certain Window progs I use MFC.

    And Ken, share your ideas while you're at it. I doubt the particular function SetItemState() is very different in the API though =P as one uses the LV_ITEM struct already which is not wrapped in MFC, but different perspectives and ideas NEVER hurt =).

  12. #12
    Registered User
    Join Date
    Aug 2001
    Posts
    15

    Lowas

    Isn't it funny that you almost never find these special little details in books or documentations?

  13. #13
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,227
    I was gonna say use SendMessage()

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. HELP!!!!emergency Problem~expert please help
    By unknowppl in forum C++ Programming
    Replies: 9
    Last Post: 08-21-2008, 06:41 PM
  2. HELP!!!!emergency ~expert please help
    By unknowppl in forum C Programming
    Replies: 1
    Last Post: 08-19-2008, 07:35 AM
  3. Create new combo boxes based on items selected in preview combo box
    By RealityFusion in forum Windows Programming
    Replies: 2
    Last Post: 01-10-2007, 09:50 AM
  4. Moving items in a ListView
    By Cactus_Hugger in forum Windows Programming
    Replies: 1
    Last Post: 01-18-2006, 09:40 PM
  5. printing out selected items only
    By Npratt23 in forum C++ Programming
    Replies: 1
    Last Post: 05-11-2005, 09:52 PM