Click here to Skip to main content
15,886,110 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 2 of 3


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 :)
 
Share this answer
 
v2
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. :)
 
Share this answer
 
it is giving "Debug Assertion Failed" while "setItemText()".
 
Share this answer
 
Please post your inserting code :)
 
Share this answer
 
I have corrected my code. now no "Debug Assertion Failed".

Now in actual scenario, i have to take data from a table and fill it in a listctrl. i have 4 columns and n- no of rows.

So i have to work on this.
You have given all idea about this. now i will work on this further. if any problem arise, i will sure mail you.

if you do have some more time, can you help me out in creating those grid line for n rows. :)

Thanks a lot for all your inputs.
 
Share this answer
 
Oops!, one more thing left in this.

Text is greater than width and it must go into next line. means "Multiline" property must be true.

You told me about "MeasureItem()". Can you give some more light on this :)
 
Share this answer
 
You could use something like this :) :

C++
void CMainForm::OnInitialUpdate()
{
  UpdateData(FALSE);
 
  m_cList.InsertColumn(0, ...);
  m_cList.InsertColumn(1, ...);
  m_cList.InsertColumn(2, ...);
  m_cList.InsertColumn(3, ...);

  FillList();
}

void CMainForm::FillList()
{
  // CRowData : public CObject
  // CObList m_Data;

  ReadTable(&m_Data);
 
  POSITION pos = m_Data.GetHeadPosition();
  while (pos) {
    CRowData* pcRowData = (CRowData*) m_Data.GetNext(pos);
    if (pcRowData) {
      int iRow = m_cList.InsertItem(0, pcRowData->GetFirstText());
      m_cList.SetItemText(iRow, 1, pcRowData->GetSecondText());
      m_cList.SetItemText(iRow, 2, pcRowData->GetThirdText());
      m_cList.SetItemText(iRow, 1, pcRowData->GetFourthText());
      m_cList.SetItemData(iRow, DWORD_PTR(pcRowData));
    }
  }
}
 
Share this answer
 
Yes this is how i am trying to do but the problem is : in "DrawItem", we have to change nItemID in "GetItemText()".

I am working on that. If You do have any suggestion, please do let me know. :)
 
Share this answer
 
You have nothing to do there :
the DrawItem() will be called for each row automatically :)

Please extend the height of your cells:
C++
BEGIN_MESSAGE_MAP(CColoredListReport, CListCtrl)
  ON_WM_MEASUREITEM_REFLECT()
END_MESSAGE_MAP()

void CColoredListReport::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)
{
  lpMeasureItemStruct->itemHeight = 50;
}


void CMainForm::RemeasureListItems()
{
  CRect cRect;
  GetWindowRect(cRect);
  WINDOWPOS wp;
  wp.hwnd = m_hWnd;
  wp.cx = cRect.Width();	
  wp.cy = cRect.Height();
  wp.flags = SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER;
  m_cList.SendMessage(WM_WINDOWPOSCHANGED, 0, (LPARAM)&wp);
}

void CMainForm::OnInitialUpdate()
{
  UpdateData(FALSE);
 
  RemeasureListItems();
 
...  
}
 
Share this answer
 
Eugen, there is one problem when i am double clicking on column border line, data is overlapping and blurring the appearance.

Can you solve this?
 
Share this answer
 
I have applied Erasebkgrnd(), and because of this blurring issue is coming into the picture

apply this code and try it:
BOOL CListForm::OnEraseBkgnd(CDC* pDC)
{
  // TODO: Add your message handler code here and/or call default
  CRect rect;
  GetClientRect(&rect);
  int r1=19,g1=40,b1=85; //Any start color
  int r2=60,g2=88,b2=156; //Any stop color

  for(int i=0;i<rect.Height();i++)
  { 
    int r,g,b;
    r = r1 + (i * (r2-r1) / rect.Height());
    g = g1 + (i * (g2-g1) / rect.Height());
    b = b1 + (i * (b2-b1) / rect.Height());
    pDC->FillSolidRect(0,i,rect.Width(),1,RGB(r,g,b));
  }
  return true;
}


if you do know how to avoid this blurring, please do let me know.
 
Share this answer
 
I could not reproduce the described effect
(or not understand its context) :)
 
Share this answer
 
I am mailing my project to you.

Build at your end. and run the application.

After this play with column black line. increase and decerase the width of column and will get that error.

or double click on column header line, column will shrink and then you increase & decrease the width, you will come to know what i am talking about.

ok.? Can i send my code to you?
 
Share this answer
 
Of course, just send me your code :)
 
Share this answer
 
I have sent it.. Please do have a look on it and suggest something on it.
 
Share this answer
 
Your drawing function
does not fill out the background
(commented pDC->FillSolidRect(..)) :)
 
Share this answer
 
Look on below code:

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);
	//cRect.DeflateRect(0, 0, 4, 4);
	//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(lpDrawItemStruct->itemID, 0), cSubItemRect, DT_LEFT);
	GetSubItemRect(lpDrawItemStruct->itemID, 1, LVIR_LABEL, cSubItemRect);
	pDC->MoveTo(cSubItemRect.TopLeft());
	pDC->LineTo(cSubItemRect.left, cSubItemRect.bottom);
	pDC->DrawText(GetItemText(lpDrawItemStruct->itemID, 1), cSubItemRect, DT_CENTER|DT_VCENTER);
	GetSubItemRect(lpDrawItemStruct->itemID, 2, LVIR_LABEL, cSubItemRect);
	pDC->MoveTo(cSubItemRect.TopLeft());
	pDC->LineTo(cSubItemRect.left, cSubItemRect.bottom);
	pDC->DrawText(GetItemText(lpDrawItemStruct->itemID, 2), cSubItemRect, DT_CENTER|DT_VCENTER);
	GetSubItemRect(lpDrawItemStruct->itemID, 3, LVIR_LABEL, cSubItemRect);
	pDC->MoveTo(cSubItemRect.TopLeft());
	pDC->LineTo(cSubItemRect.left, cSubItemRect.bottom);
	pDC->DrawText(GetItemText(lpDrawItemStruct->itemID, 3), cSubItemRect, DT_LEFT);
	break;
}
}


In my whole code, i am using fillsolidrect() only with Erasebkground.

By using which method we can avoid this blurring?
 
Share this answer
 
This thing will fill each row with same color. but i do want color in alternate rows.

And by using this method, black border line of grids are not visible.

So Any other suggestion? :)
 
Share this answer
 
Your given solution is working.

But i m loosing horizontal black line after doing this. how to get it again?
 
Share this answer
 
Eugen, I am trying to create memoryDC like button for stopping flickering of the screen but it is giving me whole listctrl black in background.


I am doing wrong somewhere, I do not know where. How this memoryDC works? Do I need to create any Region?
 
Share this answer
 

Page 2 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