I need help, please

G

Geo

Hi,

I'm using a List Control (report view) in a dialog. This
list displays 4 text items, each consisting of 3 columns.
Let's consider the following example:

Title of column1 Title c2 Title c3 Title c4
Item1 info12 info13 info14
Item2 info22 info23 info24
Item3 info32 info33 info34
Item4 info42 info43 info44

I want to change the text color of an item if a cetain
condition is true. In the example above, say I want to
change the color of the whole line of 'item2' and 'item3'.

I tried to use the CListCtrl class method SetTextColor()
and it worked so so. If I minimize the dialog and then
restore it again, the list is refreshed and it displays
all the items with the original text color.

What should I do to fix this problem or if you have
another solution to do this, please help me with it.

Thanks,
Geo
 
V

Vadim Melnik

Hi,
I'm using a List Control (report view) in a dialog. This
list displays 4 text items, each consisting of 3 columns.
Let's consider the following example:

Title of column1 Title c2 Title c3 Title c4
Item1 info12 info13 info14
Item2 info22 info23 info24
Item3 info32 info33 info34
Item4 info42 info43 info44

I want to change the text color of an item if a cetain
condition is true. In the example above, say I want to
change the color of the whole line of 'item2' and 'item3'.

I tried to use the CListCtrl class method SetTextColor()
and it worked so so. If I minimize the dialog and then
restore it again, the list is refreshed and it displays
all the items with the original text color.

What should I do to fix this problem or if you have
another solution to do this, please help me with it.

If you are using ListView Windows Common Control, see NM_CUSTOMDRAW
notification message.

...
Regards,
Vadim.
 
V

Vadim Melnik

Hi,
I am using CListCtrl and everything is working fine with
it except this text color thing. I checked the CListView
class and I'm affraid if I use it I'll have to draw
everything in the list by myself and this is hard to do.

CListCtrl is MFC wrapper for Windows ListView Common Control, I mentioned in
previous post. So everything is OK, you should not replace it with
CListView.
When I say everything, I mean I have to take care of the
text font, text color, the selecttion, drawing of
rectangles, ...

Have a look at NM_CUSTOMDRAW (list-view) notification one more time. It's
sent to the parent window of list view control. It's quite flexible
mechanism and doesn't require in entire control redrawing, it's possible to
override only for example text color. Below is code sample changing text and
background colors, it doesn't use MFC, so I'd recommend you ask this
question on MFC group and search on www.codeproject.com and www.codeguru.com
, IIRC there were a lot of samples demonstrating custom-draw in list-view
control.

<code>
LRESULT CSomeParentWnd::OnNotify_CustomDraw(int idCtrl, LPNMHDR pnmh, BOOL&
bHandled)
{
if( pnmh->hwndFrom==m_wndHistory )
{
NMLVCUSTOMDRAW* p = reinterpret_cast<NMLVCUSTOMDRAW*>(pnmh);
//ATLTRACE(_T("Stage: %d 0x%08x\n"), p->nmcd.dwDrawStage,
p->nmcd.dwDrawStage);
switch(p->nmcd.dwDrawStage)
{
case CDDS_PREPAINT:
return CDRF_NOTIFYITEMDRAW;

case CDDS_ITEMPREPAINT:
return CDRF_NOTIFYSUBITEMDRAW;

case (CDDS_ITEMPREPAINT | CDDS_SUBITEM):
{
int nIndex = static_cast<int>(p->nmcd.lItemlParam);
if( nIndex>=0 && nIndex<m_aHistory.GetSize() )
{
p->clrText = m_aHistory[nIndex]->clrText;
if( p->iSubItem==eCol_Bpm )
p->clrTextBk = m_aHistory[nIndex]->clrTextBk;
else
p->clrTextBk = m_aHistory[nIndex]->clrTextBkDef;
}
}
return CDRF_DODEFAULT;
}
}
return CDRF_DODEFAULT;
}

</code>


...
Regards,
Vadim.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top