Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Selection is gray in a CListCtrl

Selection is gray in a CListCtrl

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
28 Posts 4 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    RoyceF
    wrote on last edited by
    #1

    Hi, I have a SDI application that I show a CListCtrl-derived control using the LVS_ICON style with a 24-bit color imagelist filled with 80x80 bitmaps to represent the items in the control. When I select an item in the control, it doesn't select properly. Only the text of the item is selected and it is gray as if the control doesn't have the focus. But the control does in fact have the focus. Why doesn't the item select properly, i.e., with a blue background? Any help would be greatly appreciated, Royce -- modified at 12:47 Monday 23rd January, 2006

    D D 2 Replies Last reply
    0
    • R RoyceF

      Hi, I have a SDI application that I show a CListCtrl-derived control using the LVS_ICON style with a 24-bit color imagelist filled with 80x80 bitmaps to represent the items in the control. When I select an item in the control, it doesn't select properly. Only the text of the item is selected and it is gray as if the control doesn't have the focus. But the control does in fact have the focus. Why doesn't the item select properly, i.e., with a blue background? Any help would be greatly appreciated, Royce -- modified at 12:47 Monday 23rd January, 2006

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      RoyceF wrote:

      I have a SDI application that I show a CListCtrl-derived control...

      Are you using a CListView?


      "The words of God are not like the oak leaf which dies and falls to the earth, but like the pine tree which stays green forever." - Native American Proverb

      R 1 Reply Last reply
      0
      • D David Crow

        RoyceF wrote:

        I have a SDI application that I show a CListCtrl-derived control...

        Are you using a CListView?


        "The words of God are not like the oak leaf which dies and falls to the earth, but like the pine tree which stays green forever." - Native American Proverb

        R Offline
        R Offline
        RoyceF
        wrote on last edited by
        #3

        No, the parent of the control is the CFormView created by the CSingleDocTemplate constructor when the application is created.

        D 1 Reply Last reply
        0
        • R RoyceF

          Hi, I have a SDI application that I show a CListCtrl-derived control using the LVS_ICON style with a 24-bit color imagelist filled with 80x80 bitmaps to represent the items in the control. When I select an item in the control, it doesn't select properly. Only the text of the item is selected and it is gray as if the control doesn't have the focus. But the control does in fact have the focus. Why doesn't the item select properly, i.e., with a blue background? Any help would be greatly appreciated, Royce -- modified at 12:47 Monday 23rd January, 2006

          D Offline
          D Offline
          domehead
          wrote on last edited by
          #4

          Are you sure the ListCtrl still has focus? You might try setting up an WM_KILLFOCUS handler for the list control and running it in the debugger or something. It sounds like the control has actually lost focus, which might not be apparent because if you click on it again it temporarily gets focus, handles your click on the item, and then possibly loses focus again. Good luck! Mike Stephenson

          R 1 Reply Last reply
          0
          • D domehead

            Are you sure the ListCtrl still has focus? You might try setting up an WM_KILLFOCUS handler for the list control and running it in the debugger or something. It sounds like the control has actually lost focus, which might not be apparent because if you click on it again it temporarily gets focus, handles your click on the item, and then possibly loses focus again. Good luck! Mike Stephenson

            R Offline
            R Offline
            RoyceF
            wrote on last edited by
            #5

            I have already tried exactly what you suggest. The control is not losing the focus. Thanks for your help.

            D 1 Reply Last reply
            0
            • R RoyceF

              No, the parent of the control is the CFormView created by the CSingleDocTemplate constructor when the application is created.

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              To ascertain whether it is the actual list control or the parent object (CFormView) causing the problem, I would suggest creating a temporary dialog-based project that contains the same sort of list control. Populate the list control in exactly the same fashion. Does it behave the same as the one in the SDI project?


              "The words of God are not like the oak leaf which dies and falls to the earth, but like the pine tree which stays green forever." - Native American Proverb

              R 1 Reply Last reply
              0
              • D David Crow

                To ascertain whether it is the actual list control or the parent object (CFormView) causing the problem, I would suggest creating a temporary dialog-based project that contains the same sort of list control. Populate the list control in exactly the same fashion. Does it behave the same as the one in the SDI project?


                "The words of God are not like the oak leaf which dies and falls to the earth, but like the pine tree which stays green forever." - Native American Proverb

                R Offline
                R Offline
                RoyceF
                wrote on last edited by
                #7

                Ok, I did as you suggest. I get exactly the same behavior. The items select just the text and are a dim gray.

                R D 2 Replies Last reply
                0
                • R RoyceF

                  Ok, I did as you suggest. I get exactly the same behavior. The items select just the text and are a dim gray.

                  R Offline
                  R Offline
                  RoyceF
                  wrote on last edited by
                  #8

                  I could post my test project, but I don't know if the forum would appreciate a 130 Kbyte post.

                  1 Reply Last reply
                  0
                  • R RoyceF

                    I have already tried exactly what you suggest. The control is not losing the focus. Thanks for your help.

                    D Offline
                    D Offline
                    domehead
                    wrote on last edited by
                    #9

                    First, I'd double-verify that it's not losting focus by clicking on the control, then clicking on another control and making sure that the OnKillFocus handler is actually being called when I expect it to (it's possible depending on your message maps and parent/child relationships that the view is eating the messages). If that plays out, and you're confident that the control truly is not losing focus, could it be a problem with transparency of your images in the image list and the background color of the text (and the text not being transparent), simply not letting the blue "show through"?

                    R 1 Reply Last reply
                    0
                    • D domehead

                      First, I'd double-verify that it's not losting focus by clicking on the control, then clicking on another control and making sure that the OnKillFocus handler is actually being called when I expect it to (it's possible depending on your message maps and parent/child relationships that the view is eating the messages). If that plays out, and you're confident that the control truly is not losing focus, could it be a problem with transparency of your images in the image list and the background color of the text (and the text not being transparent), simply not letting the blue "show through"?

                      R Offline
                      R Offline
                      RoyceF
                      wrote on last edited by
                      #10

                      Yes, I have just verified that the control is not losing focus when it should not. Its OnSetFocus() and OnKillFocus() handlers are being called appropriately. When I select an item, the OnSetFocus() handler is called. The OnKillFocus() handler is not being called until I actually do move the focus. I have used different types & sizes of bitmaps and different parameters in creating the imagelist, but no change in the control's behavior.

                      J 1 Reply Last reply
                      0
                      • R RoyceF

                        Yes, I have just verified that the control is not losing focus when it should not. Its OnSetFocus() and OnKillFocus() handlers are being called appropriately. When I select an item, the OnSetFocus() handler is called. The OnKillFocus() handler is not being called until I actually do move the focus. I have used different types & sizes of bitmaps and different parameters in creating the imagelist, but no change in the control's behavior.

                        J Offline
                        J Offline
                        Joel Lucsy
                        wrote on last edited by
                        #11

                        When you select an item using the mouse, different from the that is selected by default, does it appear in blue, or grey?

                        R 1 Reply Last reply
                        0
                        • J Joel Lucsy

                          When you select an item using the mouse, different from the that is selected by default, does it appear in blue, or grey?

                          R Offline
                          R Offline
                          RoyceF
                          wrote on last edited by
                          #12

                          Selected by any means, it is always gray.

                          R J 2 Replies Last reply
                          0
                          • R RoyceF

                            Selected by any means, it is always gray.

                            R Offline
                            R Offline
                            RoyceF
                            wrote on last edited by
                            #13

                            I have just built a version of my test project using a CScrollView as the parent of the CListCtrl. It exhibits the same behavior as the dialog-based app and the CFormView-based app. That would seem to point to the images or the ImageList object that I am using. However, I have used this same ImageList & bitmaps in another project, but the selection behavior is correct.

                            1 Reply Last reply
                            0
                            • R RoyceF

                              Ok, I did as you suggest. I get exactly the same behavior. The items select just the text and are a dim gray.

                              D Offline
                              D Offline
                              David Crow
                              wrote on last edited by
                              #14

                              Can you supply a screenshot of the offending control?


                              "The words of God are not like the oak leaf which dies and falls to the earth, but like the pine tree which stays green forever." - Native American Proverb

                              R 1 Reply Last reply
                              0
                              • R RoyceF

                                Selected by any means, it is always gray.

                                J Offline
                                J Offline
                                Joel Lucsy
                                wrote on last edited by
                                #15

                                Just to be safe, does explorer highlight in blue when you select a file? Its possible to have your "scheme" have the highlight color set to gray. As another thought, is your ListView (or ListCtrl) derived from anything, meaning did you use a class from an outside source? Just wondering if perhaps you or that class might be using NM_CUSTOMDRAW to override painting. Also, what styles are being used on the view, single selection, full-row selection, show selection always, owner data, owner draw? Personally I've never seen a basic ListCtrl ever paint incorrectly without some kind of interference from code.

                                R 1 Reply Last reply
                                0
                                • D David Crow

                                  Can you supply a screenshot of the offending control?


                                  "The words of God are not like the oak leaf which dies and falls to the earth, but like the pine tree which stays green forever." - Native American Proverb

                                  R Offline
                                  R Offline
                                  RoyceF
                                  wrote on last edited by
                                  #16

                                  How do I post a bitmap or GIF?

                                  D 1 Reply Last reply
                                  0
                                  • R RoyceF

                                    How do I post a bitmap or GIF?

                                    D Offline
                                    D Offline
                                    David Crow
                                    wrote on last edited by
                                    #17

                                    You can't. You'll have to find a Web site that will allow such. There are a ton of them out there that can act as a repository.


                                    "The words of God are not like the oak leaf which dies and falls to the earth, but like the pine tree which stays green forever." - Native American Proverb

                                    R 1 Reply Last reply
                                    0
                                    • D David Crow

                                      You can't. You'll have to find a Web site that will allow such. There are a ton of them out there that can act as a repository.


                                      "The words of God are not like the oak leaf which dies and falls to the earth, but like the pine tree which stays green forever." - Native American Proverb

                                      R Offline
                                      R Offline
                                      RoyceF
                                      wrote on last edited by
                                      #18

                                      I have attached a DOC file to a thread in CodeGuru (I hope it's OK to do this) which contains a screenshot. I hope this works. Click this link: http://www.codeguru.com/forum/showthread.php?p=1315489#post1315489[^]

                                      1 Reply Last reply
                                      0
                                      • J Joel Lucsy

                                        Just to be safe, does explorer highlight in blue when you select a file? Its possible to have your "scheme" have the highlight color set to gray. As another thought, is your ListView (or ListCtrl) derived from anything, meaning did you use a class from an outside source? Just wondering if perhaps you or that class might be using NM_CUSTOMDRAW to override painting. Also, what styles are being used on the view, single selection, full-row selection, show selection always, owner data, owner draw? Personally I've never seen a basic ListCtrl ever paint incorrectly without some kind of interference from code.

                                        R Offline
                                        R Offline
                                        RoyceF
                                        wrote on last edited by
                                        #19

                                        Yes, Explorer highlights in blue, as it always has. Also, a TreeCtrl in my app which is a sibling of my ListCtrl selects correctly with a blue highlight.

                                        J 1 Reply Last reply
                                        0
                                        • R RoyceF

                                          Yes, Explorer highlights in blue, as it always has. Also, a TreeCtrl in my app which is a sibling of my ListCtrl selects correctly with a blue highlight.

                                          J Offline
                                          J Offline
                                          Joel Lucsy
                                          wrote on last edited by
                                          #20

                                          Oh, um, are you using a manifest under VC6? I know when you use manifests (to get the XP style look), imagelists behave differently. I think, but not certain by any means, that the newer compilers handle this without problems, but I'm fairly sure VC6 won't. I've found CImageList won't work quite right, I had to use the macros like ImageList_Create for it to work right.

                                          R 1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups