Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Select whole line in CListCtrl report view?

Posted on 1998-11-21
3
Medium Priority
?
318 Views
Last Modified: 2013-11-20
Does anyone have a class derived from CListCtrl that will select the entire line in report view rather than just the item?
0
Comment
Question by:duncan2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 15

Accepted Solution

by:
Tommy Hui earned 1200 total points
ID: 1325117
Make sure the list ctrl is ownerdrawn and override its DrawItem member function:

void CPublishList::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
      CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
      CRect rcItem(lpDrawItemStruct->rcItem);
      UINT uiFlags = ILD_TRANSPARENT;
      int nItem = lpDrawItemStruct->itemID;
      static _TCHAR szBuff[MAX_PATH];
      LPCTSTR pszText;
      COLORREF clrTextSave, clrBkSave;
      CRect rcLabel;
      CRect rcAllLabels;

// get item data

      LV_ITEM lvi;
      lvi.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_STATE;
      lvi.iItem = nItem;
      lvi.iSubItem = 0;
      lvi.pszText = szBuff;
      lvi.cchTextMax = sizeof(szBuff);
      lvi.stateMask = 0xFFFF;            // get all state flags
      GetItem(&lvi);

      GetItemRect(nItem, rcAllLabels, LVIR_BOUNDS);
      GetItemRect(nItem, rcItem, LVIR_LABEL);

      BOOL bSelected = lvi.state & LVIS_SELECTED;
      bSelected = bSelected || (lvi.state & LVIS_DROPHILITED);

      if (bSelected)
      {
            clrTextSave = pDC->SetTextColor(::GetSysColor(COLOR_HIGHLIGHTTEXT));
            clrBkSave = pDC->SetBkColor(::GetSysColor(COLOR_HIGHLIGHT));

            pDC->FillRect(rcAllLabels, &CBrush(::GetSysColor(COLOR_HIGHLIGHT)));
      }
      else
            pDC->FillRect(rcAllLabels, &CBrush(RGB(255,255,255)));

// draw item label

      pszText = MakeShortString(pDC, szBuff,
                        rcItem.right-rcItem.left, 2*OFFSET_FIRST);

      rcLabel = rcItem;
      rcLabel.left += OFFSET_FIRST;
      rcLabel.right -= OFFSET_FIRST;

      pDC->DrawText(pszText,-1,rcLabel,DT_LEFT | DT_SINGLELINE | DT_NOPREFIX | DT_NOCLIP | DT_VCENTER);

// draw labels for extra columns

      LV_COLUMN lvc;
      lvc.mask = LVCF_FMT | LVCF_WIDTH;

      for(int nColumn = 1; GetColumn(nColumn, &lvc); nColumn++)
      {
            rcItem.left = rcItem.right;
            rcItem.right += lvc.cx;

            int nRetLen = GetItemText(nItem, nColumn,
                                    szBuff, sizeof(szBuff));
            if (nRetLen == 0)
                  continue;

            pszText = MakeShortString(pDC, szBuff,
                  rcItem.right - rcItem.left, 2*OFFSET_OTHER);

            UINT nJustify = DT_LEFT;

            if(pszText == szBuff)
            {
                  switch(lvc.fmt & LVCFMT_JUSTIFYMASK)
                  {
                  case LVCFMT_RIGHT:
                        nJustify = DT_RIGHT;
                        break;
                  case LVCFMT_CENTER:
                        nJustify = DT_CENTER;
                        break;
                  default:
                        break;
                  }
            }

            rcLabel = rcItem;
            rcLabel.left += OFFSET_OTHER;
            rcLabel.right -= OFFSET_OTHER;

            pDC->DrawText(pszText, -1, rcLabel,
                  nJustify | DT_SINGLELINE | DT_NOPREFIX | DT_NOCLIP | DT_VCENTER);
      }

// draw focus rectangle if item has focus

      if (lvi.state & LVIS_FOCUSED)
            pDC->DrawFocusRect(rcAllLabels);

// set original colors if item was selected

      if (bSelected)
      {
        pDC->SetTextColor(clrTextSave);
            pDC->SetBkColor(clrBkSave);
      }
}

0
 

Expert Comment

by:yif
ID: 1325119
test
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

636 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