Click here to Skip to main content
12,944,475 members (51,358 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
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() :)
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 15

Try and extend it :)

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() :)

Please do not comment it out :)
  Permalink  
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 30

do you want me to comment pDC of "Erasebkground()".?

But i do want this background.

Any other suggestion?
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 32

In DrawItem(), pDC->FillSolidRect(), is already commented.

I did not get exactly what are you trying to convey.
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 33

Yes. But it may not be commented,
you should fill out the rows background with a method... :)
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 39

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

Solution 37

You could provide a function :) :
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(..))... :)
  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 :) :

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 :) :

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 :)
  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... :)

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 :)

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... :)
  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  
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
Top Experts
Last 24hrsThis month
OriginalGriff 4,651
CHill60 3,055
Maciej Los 2,423
Jochen Arndt 1,910
ppolymorphe 1,765


Advertise | Privacy | Mobile
Web02 | 2.8.170518.1 | Last Updated 6 Mar 2010
Copyright © CodeProject, 1999-2017
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