IE4 Extended Styles in a List Control

If you Ever wanted to do a full row select, be able to drag a whole column to another position, draw a grid and do some other interesting things to your CListCtrl derived class. Well now you can by setting the extended styles associated with the CListCtrl. This article will give the various flags, their uses, the applicable COMCTL32.DLL version and some code snippets used in a CListView derived class, which as you know has a CListCtrl item buried in it.

Depending on which version of the common controls DLL you have, there are extended styles which can be invoked to support a wide and interesting range of functions. You can download a free restributable version of the latest common controls DLL from Microsoft, complete with its own installer. (See www.CodeGuru.com home page for details).

Here's a description of the various extended styles available.

LVS_EX_CHECKBOXES Version 4.70. Enables check boxes for items in a list view control. Effectively, when this style is set, the control will create and set a state image list using DrawFrameControl. Check boxes are visible and functional with all list view modes. The state of the check box for a given item is obtained using the ListView_GetCheckState macro.

LVS_EX_FLATSB Version 4.71. Enables flat scroll bars in the list view. If you need more control over the appearance of the list view's scroll bars, you should manipulate the list view's scroll bars directly using the Flat Scroll Bar APIs.

LVS_EX_FULLROWSELECT Version 4.70. When an item is selected, the item and all its subitems are highlighted. This style is available only in conjunction with the LVS_REPORT style.

LVS_EX_GRIDLINES Version 4.70. Displays gridlines around items and subitems.This style is available only in conjunction with the LVS_REPORT style.

LVS_EX_HEADERDRAGDROP Version 4.70. Enables drag-and-drop reordering of columns in a list view control. This style is only available to list view controls that use the LVS_REPORT style.

LVS_EX_INFOTIP Version 4.71. The list view control sends an LVN_GETINFOTIP notification message to the parent window before displaying an item's tooltip.This style is only available to list view controls that use the LVS_ICONstyle.

LVS_EX_MULTIWORKAREAS Version 4.71. If the list view control has the LVS_AUTOARRANGE style, the control will not autoarrange its icons until one or more work areas are defined (see LVM_SETWORKAREAS). To be effective, this style must be set before any work areas are defined and any items have been added to the control.

LVS_EX_ONECLICKACTIVATE Version 4.70. The list view control sends an LVN_ITEMACTIVATE notification message to the parent window when the user clicks an item. This style also enables hot tracking in the list view control. Hot tracking means that when the cursor moves over an item, it is highlighted but not selected. LVS_EX_REGIONAL Version 4.71. The list view will create a region that includes only the item icons and text and set its window region to that using SetWindowRgn. This will exclude any area that is not part of an item from the window region. This style is only available to list view controls that use the LVS_ICON style.

LVS_EX_SUBITEMIMAGES Version 4.70. Allows images to be displayed for subitems. This style is available only in conjunction with the LVS_REPORT style.

LVS_EX_TRACKSELECT Version 4.70. Enables hover selection in a list view control. Hover selection (also called track selection) means that an item is automatically selected when the cursor remains over the item for a certain period of time. The delay can be changed from the default system setting with the LVM_SETHOVERTIME message. This style applies to all styles of list view control.

LVS_EX_TWOCLICKACTIVATE Version 4.70. The list view control sends an LVN_ITEMACTIVATE notification message to the parent window when the user double-clicks an item. This style also enables hot tracking in the list view control. Hot tracking means that when the cursor moves over an item, it is highlighted but not selected.

LVS_EX_UNDERLINECOLD Version 4.71. Causes nonhot items to be displayed with underlined text. This style is ignored if LVS_EX_ONECLICKACTIVATE is not set.

LVS_EX_UNDERLINEHOT Version 4.71. Causes hot items to be displayed with underlined text. This style is ignored if LVS_EX_ONECLICKACTIVATE or LVS_EX_TWOCLICKACTIVATE is not set.

After the creation of your view, derived from CListView, you may set the extended style of the list control using the following code. As there is currently no CListCtrl::SetExtendedStyle() you have to do a little bit of work until this method has been added.

There are two macros which support extended styles and are implemented as such:

void CDerivedListView::OnInitialUpdate()
{    
   .
   .
   .
  //The macro ListView_GetExtendedListViewStyle takes a reference to the
  // CListCtrl and returns the current extended style (a DWORD)

  DWORD dwStyle = ListView_GetExtendedListViewStyle(GetListCtrl());

 //Add the full row select and grid line style to the existing extended styles
  dwStyle |= LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES;

  //The macro ListView_SetExtendedListViewStyle takes a reference to the
  // CListCtrl and the extended style you would like to implement

  ListView_SetExtendedListViewStyle( GetListCtrl(),dwStyle);
}

Or you could send messages to the control like this:

void CDerivedListView::OnInitialUpdate()
{    
   .
   .
   .
  DWORD dwStyle;
  dwStyle = GetListCtrl().SendMessage(LVM_GETEXTENDEDLISTVIEWSTYLE, 0 ,0);
  dwStyle |= LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES ;
  GetListCtrl().SendMessage( LVM_SETEXTENDEDLISTVIEWSTYLE, 0,dwStyle );
}

But a more conventional approach would probably be:

void CDerivedListView::OnInitialUpdate()
{    
   .
   .
   .
  AddExStyle(LVS_EX_FULLROWSELECT);
  AddExStyle(LVS_EX_GRIDLINES);
}

void CDerivedListView::AddExStyle(DWORD dwNewStyle)
{
    CListCtrl& m_listctrl = GetListCtrl();
    DWORD dwStyle = m_listctrl.SendMessage(LVM_GETEXTENDEDLISTVIEWSTYLE,0,0);
    dwStyle |= dwNewStyle;
    m_listctrl.SendMessage(LVM_SETEXTENDEDLISTVIEWSTYLE, 0, dwStyle);
}



Comments

  • List control grid lines.

    Posted by Legacy on 03/04/2003 12:00am

    Originally posted by: Jag

    Hi,
    I added 3 colums to list control. The control have LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT style. I draged the vertical grid line of first column header to leftmost position so that the first column will not be shown. then i moved that to original position the vertical grid line disappears , but the column header is shown. How can i show the vertical gridlines.
    Thanks,
    Jag.

    • list box

      Posted by abhilashmkm on 07/06/2006 08:30am

      i have to draw grid lines in list box

      Reply
    Reply
  • How to print

    Posted by Legacy on 06/01/2002 12:00am

    Originally posted by: seshu

    Dear sir
    i am trying to print the contents of the listbox using right clik or with menu option . But iam failed to do this
    give me an idea.
    Regards
    seshu

    Reply
  • Where do I find the constants (what .H file) to #include?

    Posted by Legacy on 04/26/2001 12:00am

    Originally posted by: David

    What is the header file that includes all of these constants (so that I don't have to dig them up and type them into my own header file)?

    Thanks a bunch.

    Reply
  • About the Dll Version

    Posted by Legacy on 04/01/2000 12:00am

    Originally posted by: Bird

    Hello,sir

    I have a ploblem want your help, I had user VC++6.0 to develop an application ,in this application ,I use the CListCtrl and the new style--GRIDLIME, it run good in my computer, but run wrong in the other computer, in my comperter, the version of comctrl.dll is 4.72.3611.1900,the other computer , the version is 4.72.3007.0 .

    Why?

    Thanks for your help.

    Yours
    Bird

    Reply
  • Adding buttons into the scroll bar of a List Control

    Posted by Legacy on 12/08/1999 12:00am

    Originally posted by: Jean-Claude Parisio

    How can I add push buttons into the vertical scroll bar of an ownerdrawn list control (like the next/previous page buttons in a Word document) ?

    Reply
  • Bug with ListView FULLROWSELECT?

    Posted by Legacy on 09/24/1999 12:00am

    Originally posted by: Doc Davies

    I set the LVS_EX_FULLROWSELECT on a listview in VB6, when I had a column which was right aligned and contained an empty value, the full row select didn't work proberly.

    Reply
  • LVM_SETEXTENDEDLISTVIEWSTYLE

    Posted by Legacy on 07/19/1999 12:00am

    Originally posted by: Stefan Niermann

    LVM_SETEXTENDEDLISTVIEWSTYLE allows the modification of only one or more styles by passing a style mask in the wParam.

    m_listctrl.SendMessage(LVM_SETEXTENDEDLISTVIEWSTYLE, dwStyle, dwStyle) modifies only one style without retrieving the current styles.

    Ciao,
    Stefan

    Reply
  • Q:How Can I make a ListView with radio button in each grid?

    Posted by Legacy on 05/03/1999 12:00am

    Originally posted by: Lee Sung-Yub

    I'm programmer in Korea..

    I'm trying to find how to make a ListView with radio button in Each Grid.

    Programming Spec is simple, Some Kind of Event occurred by User, My program have to check what grid is checked and do something....

    but it was not simple to implement it...

    Samples in this web site, seems only to mention about ListView with Column selectable ListView or Row selectable ListView.

    But how about Grid(row/column) selectable ListView?

    And if there is any method to solve that problem and that uses comctl32.dll, please answer me what version of comctl32.dll supports it...

    I'm poor English composer..., so if there is any wrong expression in this text, please understand my text with great kindness...

    and I'm sincerely waiting for your answer.. and thanks in advance...

    Reply
  • Bug in combination of FullRow and Gridlines ?

    Posted by Legacy on 04/12/1999 12:00am

    Originally posted by: Daniel Schmid

    When I use LVS_EX_FULLROWSELECT and LVS_EX_GRIDLINES as extended styles, the first row is less height than the following ones. By selecting a row, the selection rectangle is shifted down for the amount of pixels the first row is smaller.
    How can this be fixed?

    Reply
  • How do you take advantage of the LVS_EX_SUBITEMIMAGES ex_style?

    Posted by Legacy on 01/13/1999 12:00am

    Originally posted by: Kevin Treanor

    How do you use LVS_EX_SUBITEMIMAGES flag. I can't seem to get a image in a sub item.

    Thanks in advance

    Kev

    Reply
  • Loading, Please Wait ...

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

  • Live Event Date: November 20, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT Are you wanting to target two or more platforms such as iOS, Android, and/or Windows? You are not alone. 90% of enterprises today are targeting two or more platforms. Attend this eSeminar to discover how mobile app developers can rely on one IDE to create applications across platforms and approaches (web, native, and/or hybrid), saving time, money, and effort and introducing apps to market faster. You'll learn the trade-offs for gaining long …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds