Results 1 to 4 of 4

Thread: Bizarre list view behavior [Resolved once more!]

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2002
    Location
    Oregon
    Posts
    64

    Bizarre list view behavior [Resolved once more!]

    I have a list view set to the report style. I want to be able to change the back ground color of some of the items. For example, some of them should have a red back ground, while others will be blue, and the rest the default white. Is this possible?
    Last edited by Arawn; Jan 20th, 2003 at 11:15 AM.

  2. #2

    Thread Starter
    Lively Member
    Join Date
    May 2002
    Location
    Oregon
    Posts
    64
    Figured it out! Turns out the common controls will notify when it's about to paint the control and it's items (And subitems if you tell it to). You just have to catch it in the WM_NOTIFY message.

    Code:
    case WM_NOTIFY:
    	NMLVCUSTOMDRAW *nmLV;
    
    	nmLV = (LPNMLVCUSTOMDRAW)lParam;
    	if (nmLV->nmcd.dwDrawStage == CDDS_PREPAINT)
    	{
    		return CDRF_NOTIFYITEMDRAW;
    	}
    	else if (nmLV->nmcd.dwDrawStage == CDDS_ITEMPREPAINT)
    	{
    /* Do what you please here, set text and bk colors and so on and so forth */
    		return CDRF_DODEFAULT;
    	}
    	break;

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2002
    Location
    Oregon
    Posts
    64
    Ok, I was close. The code I posted above worked until I attempted to resize a column, then a got a nasty access violation. But I took a look at an example on MSDN and made my code look like this:

    Code:
    case WM_NOTIFY:
    	NMLVCUSTOMDRAW *nmLV;
    	int i;
    
    	nmLV = (LPNMLVCUSTOMDRAW)lParam;
    	i = nmLV->nmcd.dwItemSpec % 3;
    	switch(nmLV->nmcd.dwDrawStage)
    	{
    		case CDDS_PREPAINT:
    			return CDRF_NOTIFYITEMDRAW;
    	
    	
    		case CDDS_ITEMPREPAINT:
    			switch (i)
    			{			
    				case 0:
    					nmLV->clrTextBk = RGB(255, 255, 255);
    					break;
    				case 1:
    					nmLV->clrTextBk = RGB(214, 211, 206);
    					break;
    				case 2:
    					nmLV->clrTextBk = RGB(204, 204, 153);
    					break;
    			}
    			return CDRF_NOTIFYSUBITEMDRAW;
    
    	}		
    	
    
    
    	return CDRF_DODEFAULT;
    This seems to look great, I get alternating lines of white, grey, and a goldish color. And I can resize the columns, EXCEPT the second one (1 in the index of columns). I can't do it as a user, or by calling functions/sending messages to the control itself. It seems to lock down that column. This all seems to be caused by returning CDRF_NOTIFYITEMDRAW. If I comment that out I can resize all of them, but I don't get my colors. I suppose I could make a column that goes in its place with a width of 0 but that seems like a half-assed hack to me. What could be locking the width of that column?

  4. #4

    Thread Starter
    Lively Member
    Join Date
    May 2002
    Location
    Oregon
    Posts
    64

    Talking

    Finally figured it out! (again) I forgot to check to make sure the message was coming from the ListView, and the first time around I was only checking the the ID, not the hwnd. Anyway, life is good. My original goal of this project was to learn how to make and ODBC connection to a DB and retreive data, and so far that was the easy part, presenting the data has been the bigger b*tch. But anyway, thanks for letting me ramble, and I hope someone in the future can use my frustrations.

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