Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ MFC
Hello,
 
I do want to display multiline text in ListCtrl of Report View Style.
While displaying data, i do want black color grid lines in Reoprt View Style.
 
Anyone can help me out in this?
Posted 3-Mar-10 19:33pm
AJ831.2K
Page 1 of 3

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 31

No. The error source is placed at your DrawItem() Smile | :)
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 15

Try and extend it Smile | :)
 
void CMainForm::OnInitialUpdate()
{
  UpdateData(FALSE);
 
  m_cList.InsertColumn(0, _T("col 1"), LVCFMT_LEFT, 200);
  m_cList.InsertColumn(1, _T("col 2"), LVCFMT_LEFT, 200);
  m_cList.InsertItem(0, _T("item 1"));
  m_cList.SetItemText(0, 1, _T("comment 1"));
  m_cList.InsertItem(1, _T("item 2"));
  m_cList.SetItemText(1, 1, _T("comment 2"));
  m_cList.InsertItem(2, _T("item 3"));
  m_cList.SetItemText(2, 1, _T("comment 3"));
  m_cList.InsertItem(3, _T("item 4"));
  m_cList.SetItemText(3, 1, _T("comment 4"));
}
 
void CColoredListReport::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
  CDC* pDC;
  pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
 
  switch (lpDrawItemStruct->itemAction) {
   case ODA_DRAWENTIRE:
     CRect cRect(lpDrawItemStruct->rcItem);
     cRect.DeflateRect(0, 0, 1, 1);
     pDC->FillSolidRect(cRect, RGB(255, 249, 121));
     
     // The row frame
     pDC->MoveTo(cRect.left, cRect.bottom);
     pDC->LineTo(cRect.right, cRect.bottom);
     pDC->LineTo(cRect.right, cRect.top -1);
     
     // The cells frames and textes
 
     CRect cSubItemRect;
     GetSubItemRect(lpDrawItemStruct->itemID, 0, LVIR_LABEL, cSubItemRect);
     pDC->DrawText(GetItemText(0, 0), cSubItemRect, DT_CENTER|DT_VCENTER);
 
     GetSubItemRect(lpDrawItemStruct->itemID, 1, LVIR_LABEL, cSubItemRect);
     pDC->MoveTo(cSubItemRect.TopLeft());
     pDC->LineTo(cSubItemRect.left, cSubItemRect.bottom);
     pDC->DrawText(GetItemText(0, 1), cSubItemRect, DT_CENTER|DT_VCENTER);
  
     break;
  }
}
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 35

You should use pDC->FillSolidRect(cRect, <YourRGB>);
 
in your DrawItem() Smile | :)
 
Please do not comment it out Smile | :)
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 39

Please take cRect.DflateRect(0, 0, 1, 1); again Smile | :)
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 37

You could provide a function Smile | :) :
COLORREF CColoredListReport::GetColorByIndex(int iRow)
{
  COLORREF crResult = iRow % 2 ? RGB(x, y, z) : RGB(z, x, y);
  return crResult;
}
...and the use it in DrawItem():
...
  pDC->FillSolidRect(cRect,
                     GetColorByIndex(lpDrawItemStruct->itemID));
...
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You could try to remove the grig style
and frame your owner draw cells with black lines:
each cell - at its bottom and right sides (CYourList::DrawItem(..))... Smile | :)
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

do you haev any sample code for this so that i can proceed?
 
well i have already started working on this.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Your possible beginning Smile | :) :
 
void CYourList::DrawItem(LPDRAWITEMSTRUCT pDIS)
{
  CDC* pcDC = CDC::FromHandle(pDIS->hDC);
 
  switch (pDIS->itemAction) {
    case ODA_DRAWENTIRE: {
      CRect cItemRect(pDIS->rcItem);
      pcDC->MoveTo(cItemRect.left,  cItemRect.bottom);
      pcDC->LineTo(cItemRect.right, cItemRect.bottom);
      pcDC->LineTo(cItemRect.right, cItemRect.top);
...
    }
    break;
  }
}
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Eugen,
 
My requirement is: alternated row is of yellow color with multiline property true.
 
And grid line must be of black color.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

control is not coming to "DrawItem()".
My Owner Data & Owner Draw Fixed is TRUE.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 6

Now it is yellow Smile | :) :
 
void CYourList::DrawItem(LPDRAWITEMSTRUCT pDIS) {
  CDC* pcDC = CDC::FromHandle(pDIS->hDC);
  switch (pDIS->itemAction) {
    case ODA_DRAWENTIRE: {
      CRect cItemRect(pDIS->rcItem);
      pcDC->FillSolidRect(cItemRect, RGB(255, 249, 121));
      pcDC->MoveTo(cItemRect.left,  cItemRect.bottom);
      pcDC->LineTo(cItemRect.right, cItemRect.bottom);
      pcDC->LineTo(cItemRect.right, cItemRect.top);
...
    }
    break;
  }
}
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 7

Please post your list class,
its implementation and parents exchange Smile | :)
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 8

List Class:
 
Header File:
class CColoredListReport : public CListCtrl
{
	DECLARE_DYNAMIC(CColoredListReport)
public:
	CColoredListReport();
	virtual ~CColoredListReport();
protected:
	DECLARE_MESSAGE_MAP()
public:
	virtual void DrawItem(LPDRAWITEMSTRUCT /*lpDrawItemStruct*/);
};
 
CPP File:
void CColoredListReport::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
 // TODO:  Add your code to draw the specified item

 CDC* pDC;
 pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
 
 switch (lpDrawItemStruct->itemAction)
 {
   case ODA_DRAWENTIRE:
     CRect cRect(lpDrawItemStruct->rcItem);
     pDC->MoveTo(cRect.left, cRect.bottom);
     pDC->LineTo(cRect.right, cRect.bottom);
     pDC->LineTo(cRect.right, cRect.top);
 
     break;
  }
}
 
Parent Class:
void CListForm::DoDataExchange(CDataExchange* pDX)
{
    CFormView::DoDataExchange(pDX);
 
    DDX_Control(pDX, IDC_LIST1, m_lstReportView);
}
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 9

There is nothing to draw,
you should insert some columns and items... Smile | :)
 
For example, in the virtual void CMainForm::OnInitialUpdate():
void CMainForm::OnInitialUpdate()
{
  UpdateData(FALSE);
 
  m_cList.InsertColumn(0, _T("Column 1"));
 
  m_cList.InsertItem(0, _T("item 1"));
  m_cList.InsertItem(1, _T("item 2"));
  m_cList.InsertItem(2, _T("item 3"));
  m_cList.InsertItem(3, _T("item 4"));
}
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 10

First of all control is not going to "DrawItem()".
 
Second, I am accessing m_lstReportView from CListForm.
 
Above of all this, i have create my own List Ctrl which include black color grid line with alternate colored row. Firstly i have to achieve this later i will do inserting.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 11

Very good Smile | :)
 
But the conrol would go there
when it will be necessary, for example - to draw an item.
 
There are no items in your list control now... Smile | :)
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 12

ohh. k I got your point.
 
Yes, control is now going there. but it is drawing only horizontal line but not vertical one.
 
and also it is not displaying inserted item.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 13

Try to decrement the dimensions of the drawing rectangle first:
...
  cRect.DeflateRect(0, 0, 1, 1);
...
The text could be obtained by CString CListCtrl::GetItemText(iItem, iSubItem)
 
and then drawn in the subitems rectangle (CListCtrl::GetSubItemRect())...
Good luck Smile | :)
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 14

Eugen, I am trying but i am not able to understand how and where to use these functions.
 
in "DrawItem", i tried but i got "Debug Assertion Failed".
 
Do some needful once again for me. Smile | :)
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 16

it is giving "Debug Assertion Failed" while "setItemText()".
  Permalink  
Page 1 of 3
1 2 3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 _Amy 310
1 OriginalGriff 294
2 Nirav Prabtani 268
3 Sergey Alexandrovich Kryukov 211
4 CHill60 150
0 OriginalGriff 7,889
1 Sergey Alexandrovich Kryukov 7,006
2 Maciej Los 4,014
3 Peter Leow 3,708
4 CHill60 2,762


Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 6 Mar 2010
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100