Click here to Skip to main content
15,885,914 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
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

Page 1 of 3


No. The error source is placed at your DrawItem() :)
 
Share this answer
 
Try and extend it :)

C++
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;
  }
}
 
Share this answer
 
You should use pDC->FillSolidRect(cRect, <YourRGB>);

in your DrawItem() :)

Please do not comment it out :)
 
Share this answer
 
v2
do you want me to comment pDC of "Erasebkground()".?

But i do want this background.

Any other suggestion?
 
Share this answer
 
In DrawItem(), pDC->FillSolidRect(), is already commented.

I did not get exactly what are you trying to convey.
 
Share this answer
 
Yes. But it may not be commented,
you should fill out the rows background with a method... :)
 
Share this answer
 
Please take cRect.DflateRect(0, 0, 1, 1); again :)
 
Share this answer
 
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));
...
 
Share this answer
 
v2
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(..))... :)
 
Share this answer
 
do you haev any sample code for this so that i can proceed?

well i have already started working on this.
 
Share this answer
 
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;
  }
}
 
Share this answer
 
Eugen,

My requirement is: alternated row is of yellow color with multiline property true.

And grid line must be of black color.
 
Share this answer
 
control is not coming to "DrawItem()".
My Owner Data & Owner Draw Fixed is TRUE.
 
Share this answer
 
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;
  }
}
 
Share this answer
 
Please post your list class,
its implementation and parents exchange :)
 
Share this answer
 
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:
C#
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:
C#
void CListForm::DoDataExchange(CDataExchange* pDX)
{
    CFormView::DoDataExchange(pDX);

    DDX_Control(pDX, IDC_LIST1, m_lstReportView);
}
 
Share this answer
 
There is nothing to draw,
you should insert some columns and items... :)

For example, in the virtual void CMainForm::OnInitialUpdate():
C++
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"));
}
 
Share this answer
 
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.
 
Share this answer
 
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... :)
 
Share this answer
 
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.
 
Share this answer
 

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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900