Owner drawn control
One of the styles that the listview control can have is the LVS_OWNERDRAWFIXED style. The implication of this style is that the responsibility of drawing the content of the control is on the application. That is, you have to write all the code for drawing and displaying text in the control. Another aspect of the LVS_OWNERDRAWFIXED style is that all the rows should have the same height. The height of a row is set when the parent window responds to the WM_MEASUREITEM message when the control is created. If this height is not satisfactory, you can change it by using the technique discussed in the topic "Changing row height in owner drawn control" .
The virtual function DrawItem() is called for each row that needs to be painted. This function is responsible for drawing the entire row including the state image, the item image, the item label and the sub-labels. The default implementation of this function simply asserts. This means that there is not short cut for implementing this function. Besides drawing the images and the texts, you also have to set the hightlight color if the row is selected and the focus rectangle if the row has focus. All this makes the implementation of the DrawItem() function somewhat tedious but allows a great deal of customization.
Here are few things we can do with an owner drawn list view control. We can implement full row selection where the full row is highlighted rather than just the first column of the row. We can use different background colors and text colors for different rows, columns and even different cells. We can also display icons in any column. The owner drawn control can also be used to show a background image.
For code to implement owner drawn CListCtrl see the topic "Selection highlighting of entire row".

Comments
Full row select for CListCtrl
Posted by Legacy on 08/15/2003 12:00amOriginally posted by: Jim Revett
To show full row selection just set the style as follows:
Where m_ctrllcSwitchLIst is the CListCtrl variable.
// Sets full row select
Replym_ctrllcSwitchList.SetExtendedStyle(m_ctrllcSwitchList.GetExtendedStyle()| LVS_EX_FULLROWSELECT);
How to display a resource image that is bigger than an icon in a listview???!!!
Posted by Legacy on 12/29/2002 12:00amOriginally posted by: alien
I'm realy in a big trouble here...If someone could help me i'd realy appriciate any hint, or code...
I have a recource that is an image 75x100 pixels, and 32bit color depth!!!
I want to display this image as an 'icon' for every element.
I'd initialized a the imageList with the picture, with a correct image...'till now is O.K.!
Now when i want to display the elements it doesn't apear, but when i select an item the selection is set to the coresponding size (70x100).
I was wandering why the pciture doesn't apear?!
The imagelist is loaded, the picture is set! Why the f... ?!
I've no idea why?!
Thanks for anyone for the help they can give me!!!
With repsect Balint 'alien' Attila :)
ReplyHow to make ActiveX control background transparent
Posted by Legacy on 06/21/2002 12:00amOriginally posted by: Ujjal
Do you have a clue how to make activeX control background transparent?
ReplyHelp Me!!!
Posted by Legacy on 04/24/2002 12:00amOriginally posted by: andy
Hi,
I success Transparent textbkcolor.
lplvcd->clrTextBk = CLR_NONE;
But there's another problem.
If i select one row, that's textbkcolor become black.
And i select another row, black row don't become transparent.
Just black textbkcolor.
How can i transparent bkcolor after lost focus?
Help me!
void CMyListCtrl::OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult)
{
*pResult = 0;
LPNMLVCUSTOMDRAW lplvcd = (LPNMLVCUSTOMDRAW)pNMHDR;
switch(lplvcd->nmcd.dwDrawStage)
{
case CDDS_PREPAINT:
{
*pResult = CDRF_NOTIFYITEMDRAW;
return;
}
case CDDS_ITEMPREPAINT:
{
int nItem = static_cast( lplvcd->nmcd.dwItemSpec );
lplvcd->clrTextBk = CLR_NONE;
*pResult = CDRF_NOTIFYPOSTPAINT;
Replyreturn;
}
}
}
how to change the list control header
Posted by Legacy on 04/05/2002 12:00amOriginally posted by: cjy
please tell me how to add a image to list control header
Replyvery thanks
List View Control
Posted by Legacy on 12/01/2001 12:00amOriginally posted by: Agus Budiman
It seems that the virtual function DrawItem() is only called when the ownerdraw list view control is in REPORT view. Can anyone show me how to cause the DrawItem() to be invoked in other views (large view, small icon view, and list view)
Thanks
ReplyRotating painted view 90 degrees?
Posted by Legacy on 11/26/2001 12:00amOriginally posted by: Joachim Wickman
ReplyStatusbarCtrl on the top of the ListView list control !!
Posted by Legacy on 05/25/2000 12:00amOriginally posted by: Thanigai Murugan K.
How do I add a StatusBarCtrl on the top of the ListView-ListCtrl?.. (Like in Visual Source Safe 6.0..
Any Idea?...
Thanks i advance,
ReplyThanigai Murugan K.
Where is the demo code?
Posted by Legacy on 10/26/1999 12:00amOriginally posted by: Jack2001
Where is the demo code doing ownerdraw listview. For example, if I need to fill every cell on the second colume with different colors how do I do it?
ReplyDisplaying icons in each column
Posted by Legacy on 10/05/1999 12:00amOriginally posted by: David Champagne
Could you show me how to display icons in any column?
Thanks a lot,
ReplyDavid
Loading, Please Wait ...