|
|
Simple and clear
very help to me
|
|
|
|
|
Hi,
Thanks for this kind of good article. I tried your code, but for a List control having no items it doesn't show the alternate colors correctly. When there are items only the rows having the items gets the background color. When i checked the code, i found that GetItemPosition fails. This happens in VS2008. When i run your code using VS2005 it works. The problem is with the GetItemPosition. Any idea's
Thanks
Nitheesh.
Jose Jo Martin
http://www.simpletools.co.in
|
|
|
|
|
If you activate LVS_EX_DOUBLEBUFFER for the CListCtrl you will have the following redraw issues:
* the non column data area is not painted initially
* when you scroll the non column area modified is not painted
* when you select a record it will clean (paint white) an additional area after the selection. This will break backgrounds.
Double buffer is an important feature of CListCtrl that helps makes resizing and scrolling very smooth.
Best regards,
Sorin Sbarnea
|
|
|
|
|
I m also having the same painting problems.please tell me how can i resolve this?
|
|
|
|
|
|
hello
I have a question.
Is it possible to change the color of an entire row via your control class?
Also: if I want to select a row from my code, and change the color to indicate that it has been selected via the code, not the result of the user clicking the row, is this possible?
Thank you.
A.T
|
|
|
|
|
change the m_colRow1 and m_colRow2 variables or create a new method for this purpose.
sdancer75
|
|
|
|
|
Hi,
its such a nice code.
here if list is empty the alternate row color not displayed.
is this possible is the list is empty,still alternate row colors are visible.
please help me for this.
thanks in advance.
To accomplish great things, we must not only act, but also dream;
not only plan, but also believe.
|
|
|
|
|
Hey,
Your article was really very helpful. But my problem is how i can change Color of lines separating items in CListCtrl in report view(grid style) .
Thanks
|
|
|
|
|
Go to the source code and change the variables m_colRow1 & m_colRow2 you will found in the contructor with the prefered colors like this
m_colRow1 = RGB(255,0,0) --> make Row1 Red
Regards,
sdancer75
|
|
|
|
|
Hey ! Plz read the problem carefully. I am not interested in changing color of the alternate rows instead of that i am looking for the changing color of the grid lines.
|
|
|
|
|
Hmm,
I dont think that I have a solution for you. But an idea is to disable the grid line option and then try to design them by your own in the ErasaBackground virtual method.
Hope that it will help,
Regards,
sdancer75
|
|
|
|
|
I'd like to use this in my commercial product, do you require licensing to be followed regarding this component?
|
|
|
|
|
Nope its free to use and to modify. Just refer my name as the original author.
Thanks for asking !
sdancer75
|
|
|
|
|
Hi I tried to use this functionality in dialog based application.
But Dialog loosing its image, a transparent dialog is showing.
How to over come this in Dialog Based Apps.
|
|
|
|
|
I use your code in my project ,but when add data,color back is not appear in data area else is appear,Why?
|
|
|
|
|
Did you adjusted the m_colRow1 & m_colRow2 variables ? Did you changed the textbackground color for your data? Check once again the example ! Below i am giving a snip of my code.
It just creates the CListCtrl object, adjust the font, define the columns and after that it fills it from a database. There is nothing tricky here !!
----- creates the object ----------
m_ListCtrl.Create( LVS_REPORT | LVS_SHOWSELALWAYS | LBS_NOTIFY, CRect(0,0,400,200), this, IDC_LISTCTRL );
m_ListCtrl.SetExtendedStyle(LVS_EX_FLATSB | LVS_EX_HEADERDRAGDROP | LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT );
------ sets the font ---------
CFont fArial;
fArial.CreatePointFont (100,"System");
m_ListCtrl.SetFont(&fArial);
----- define the columns --------
GetClientRect(r);
//m_ListCtrl.SetColumnWidth (0,r.right /3);
m_ListCtrl.SetColumnWidth (1,r.right /3);
m_ListCtrl.SetColumnWidth (2,r.right /3);
m_ListCtrl.SetColumnWidth (3,(r.right /3) /2 );
m_ListCtrl.SetColumnWidth (4,(r.right /3) /2 );
m_ListCtrl.SetWindowPos (&wndTop,0,0,r.right,r.bottom ,SWP_SHOWWINDOW);
m_ListCtrl.InsertColumn (0,_T("column1"),LVCFMT_CENTER);
m_ListCtrl.InsertColumn (1,_T("column2"),LVCFMT_LEFT);
m_ListCtrl.InsertColumn (2,_T("column3"),LVCFMT_LEFT);
m_ListCtrl.InsertColumn (3,_T("column4"),LVCFMT_CENTER);
m_ListCtrl.InsertColumn (4,_T("column5"),LVCFMT_CENTER);
-------- inserts data from a database ------
m_ListCtrl.InsertItem(counter,_T(strVal));
pRs->GetFieldValue("Title", strVal);
m_ListCtrl.SetItemText(counter,1,_T(strVal));
pRs->GetFieldValue("Author1", strVal);
m_ListCtrl.SetItemText(counter,2,_T(strVal));
pRs->GetFieldValue("PublishHouseDesc", strVal);
m_ListCtrl.SetItemText(counter,3, _T(strVal));
pRs->GetFieldValue("CategoryDesc", strVal);
m_ListCtrl.SetItemText(counter,4, _T(strVal));
Regards,
sdancer75
|
|
|
|
|
Thanks for you reply,i seek my code and find finger out,because i am not use Create method create this listctrl,i was Drag a listctrl Controls,and i use the create method ,it's ok~ Thank you very much!
|
|
|
|
|
Hi,
Here is my CustomDrawList class in the following. can you tell me how to implement your solution (cloredList)?
Thanks,
// CustomDrawList.cpp : implementation file
#include "stdafx.h"
#include "CustomDrawList.h"
// CCustomDrawList
IMPLEMENT_DYNAMIC(CCustomDrawList, CListCtrl)
CCustomDrawList::CCustomDrawList()
{
}
CCustomDrawList::~CCustomDrawList()
{
}
BEGIN_MESSAGE_MAP(CCustomDrawList, CListCtrl)
ON_WM_CTLCOLOR()
ON_WM_VSCROLL()
END_MESSAGE_MAP()
// CCustomDrawList message handlers
HBRUSH CCustomDrawList::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
return (HBRUSH)::GetStockObject(NULL_BRUSH);
}
void CCustomDrawList::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
// TODO: Add your message handler code here and/or call default
CListCtrl::OnVScroll(nSBCode, nPos, pScrollBar);
}
//CustomDrawList.h
#pragma once
// CCustomDrawList
class CCustomDrawList : public CListCtrl
{
DECLARE_DYNAMIC(CCustomDrawList)
public:
CCustomDrawList();
virtual ~CCustomDrawList();
protected:
DECLARE_MESSAGE_MAP()
public:
afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
};
|
|
|
|
|
hi,
its farily simple. Just plug the onDraw to your custom control and do the appropriate changes to the color.
Regards,
sdancer75
|
|
|
|
|
.... to the OnEraseBkgnd i meant, sorry.
sdancer75
|
|
|
|
|
Can you implement your code into my above code?
Thanks,
|
|
|
|
|
|
Does anyone know how to implement this in a CListView?
TIA
Tony
|
|
|
|
|