Solved

Hi-liting/Shading a string in a CListBox?

Posted on 1998-05-05
7
246 Views
Last Modified: 2013-11-20
I have derived a class from CListBox and made it owner draw.  I have also updated the DrawItem() function to draw the strings that are added to the list box.  Now my problem is, once the user double-clicks on the string I'd like to have it remain shaded gray.  How do I do this? Help!
0
Comment
Question by:tdubroff
  • 3
  • 3
7 Comments
 
LVL 15

Expert Comment

by:Tommy Hui
ID: 1307627
What exactly do you mean by remain shaded gray? Do you mean as if it wasn't selected? Or if it is selected?

Regardless, the code you have for owner-draw determines exactly how the items are to be displayed. I suspect you probably have code in there to check if the state is selected or focused and to draw something different. One of those can be combined to achieve the effect you want.

For example, if you want it to appear selected whether the listbox has focus or not, then remove the check for the focused state because that is no longer needed.

Note that you can also change the selected state of the item when the user double clicks on it. If you don't want it to be selected after double clicking, then add the code to turn off the selection.
0
 
LVL 2

Author Comment

by:tdubroff
ID: 1307628
I have a list box that is filled with several strings.  Once the user double-clicks on each item, then that item gets selected and is displayed with a blue background.  When the user selects a different item, then I want the original item to be displayed with a gray background (meaning that it has been selected before).
0
 
LVL 10

Accepted Solution

by:
RONSLOW earned 60 total points
ID: 1307629
OK .. in your derived class, associate some data with each listbox entry.  This data will (include) a flag to say "I have been selected".  In your owner-draw code, look at the associated data for the item you are drawing and set the colours appropriately.

Check out the source code for the MFC class CCheckListBox which uses an ownerdran listbox to show (and respond to) a check box on each line.  This also associates a flag with each item for its check state and draws the checkbox accordingly.

0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 2

Author Comment

by:tdubroff
ID: 1307630
Thanks RONSLOW.  Once again I have gotten something working using your suggestions.  However my problem is not quite done.  The user can if he/she wants press a button which will un-gray all grayed items.  The question is then, how do I cause a refresh of the list box (how do I force DrawItem to be called)?  
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1307631
Invalidate() it.

0
 
LVL 2

Author Comment

by:tdubroff
ID: 1307632
Thanks a bunch!
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1307633
Don't you just love two-word answers - short and to the point :-).

Glad I could help !!
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Expand macro to ask for filename column 8 37
countEvens challenge 2 97
Bartender label printing - switch on and off graphics 3 36
Problem to App source 6 32
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

815 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now