I need help, please

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Geo

    #1

    I need help, please

    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
  • Vadim Melnik

    #2
    Re: I need help, please

    Hi,
    [color=blue]
    > 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.[/color]

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

    ...
    Regards,
    Vadim.


    Comment

    • Vadim Melnik

      #3
      Re: I need help, please

      Hi,
      [color=blue]
      > 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.[/color]

      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.
      [color=blue]
      > When I say everything, I mean I have to take care of the
      > text font, text color, the selecttion, drawing of
      > rectangles, ...[/color]

      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_Custo mDraw(int idCtrl, LPNMHDR pnmh, BOOL&
      bHandled)
      {
      if( pnmh->hwndFrom==m_wn dHistory )
      {
      NMLVCUSTOMDRAW* p = reinterpret_cas t<NMLVCUSTOMDRA W*>(pnmh);
      //ATLTRACE(_T("St age: %d 0x%08x\n"), p->nmcd.dwDrawSta ge,
      p->nmcd.dwDrawSta ge);
      switch(p->nmcd.dwDrawSta ge)
      {
      case CDDS_PREPAINT:
      return CDRF_NOTIFYITEM DRAW;

      case CDDS_ITEMPREPAI NT:
      return CDRF_NOTIFYSUBI TEMDRAW;

      case (CDDS_ITEMPREPA INT | CDDS_SUBITEM):
      {
      int nIndex = static_cast<int >(p->nmcd.lItemlPar am);
      if( nIndex>=0 && nIndex<m_aHisto ry.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.


      Comment

      Working...