GIDForums  

Go Back   GIDForums > Computer Programming Forums > MS Visual C++ / MFC Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 30-Sep-2005, 05:01
shvalb
 
Posts: n/a
Question

Changing the text color of 1 record in a CListCtrl


Hi.

I use CListCtrl that is set to a 'Report' view.
I Inserted 10 lines using the SetItemText() method.

My question is, can I set some of the ClistCtrl records/Lines to be in default black color and some in a different color ?? how can I control the color of the text that I insert to the control??

Another question, I overrided the 'double click' method when doule clicking on the CList control, and it works only if I double click on the first most left column of the control, suppose I have more then 1 column, how can I set the double click event for the 2nd or 3rd column ??

Thanks alot!
  #2  
Old 30-Sep-2005, 09:50
aie0 aie0 is offline
Member
 
Join Date: Dec 2004
Posts: 246
aie0 is a jewel in the roughaie0 is a jewel in the rough

Re: Changing the text color of 1 record in a CListCtrl


NM_CUSTOMDRAW should do the trick:
CPP / C++ / C Code:

ON_NOTIFY_REFLECT ( NM_CUSTOMDRAW, OnCustomdraw )

void CMyDlg::OnCustomdrawMyList ( NMHDR* pNMHDR, LRESULT* pResult )
{
NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );

    // Take the default processing unless we set this to something else below.
    *pResult = CDRF_DODEFAULT;

    // First thing - check the draw stage. If it's the control's prepaint
    // stage, then tell Windows we want messages for every item.

    if ( CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage )
        {
        *pResult = CDRF_NOTIFYITEMDRAW;
        }
    else if ( CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage )
        {
        // This is the prepaint stage for an item. Here's where we set the
        // item's text color. Our return value will tell Windows to draw the
        // item itself, but it will use the new color we set here.
       
        COLORREF crText;

        if ((pLVCD->nmcd.dwItemSpec  == 0 ) // first line
            crText = RGB(255,0,0);
        
        // Store the color back in the NMLVCUSTOMDRAW struct.
        pLVCD->clrText = crText;

        // Tell Windows to paint the control itself.
        *pResult = CDRF_DODEFAULT;
        }
}


About the second question:
Use LVS_EX_FULLROWSELECT style for your list control
CPP / C++ / C Code:
// Initial extended style for the list control on this dialog
	DWORD dwStyle = m_cListCtrl.GetExtendedStyle();
	dwStyle |= LVS_EX_FULLROWSELECT;
	m_cListCtrl.SetExtendedStyle(dwStyle);
 
 

Recent GIDBlogStupid Management Policies by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
need help on text file analyser ffantasy C Programming Language 1 05-Sep-2005 14:44
changing colour of individual items of control created through CListCtrl Sadia MS Visual C++ / MFC Forum 0 01-Jul-2005 09:09
changing caption of static text control Pandiani MS Visual C++ / MFC Forum 1 20-Sep-2004 02:38
CD burner wont burn!! robertli55 Computer Hardware Forum 1 18-Jun-2004 11:53
Yet another CD burner problem: Lite-On LSC-24082K Erwin Computer Hardware Forum 1 22-May-2004 12:28

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 10:22.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.