Share via


Adding Columns (Windows CE 5.0)

Send Feedback

Columns control the way in which items and their subitems are displayed in report view. Each column has a title and a width, and is associated with a specific subitem. The attributes of a column are defined by an LVCOLUMN structure.

To add a column to a list view control, use the LVM_INSERTCOLUMN message. To delete a column, use the LVM_DELETECOLUMN message. You can retrieve and change the properties of an existing column by using the LVM_GETCOLUMN and LVM_SETCOLUMN messages. To retrieve or change a column width, use the LVM_GETCOLUMNWIDTH and LVM_SETCOLUMNWIDTH messages.

Unless the LVS_NOCOLUMNHEADER window style is specified, column headers appear in report view. A user can tap a column header, which causes the list view control to send an LVN_COLUMNCLICK message to the parent window. Typically, the parent window sorts the list view control by the specified column when a user taps the column header.

List view controls can set the order in which columns are displayed. To use this functionality, specify the LVCF_ORDER value and assign the proper value to the iOrder member in the LVCOLUMN structure. To check the format field in the LVCOLUMN structure, use an operator. Always add text to the column header.

The following code example shows how to add columns and set the number of items in the list view window.

BOOL InitListView (HWND hwndListView)
{
  int index;                      
  LV_COLUMN lvColumn;        
  TCHAR szString[5][20] = {TEXT("Main Column"), 
                           TEXT("Column 1"), 
                           TEXT("Column 2"), 
                           TEXT("Column 3"), 
                           TEXT("Column 4")};

  // Empty the list in list view.
  ListView_DeleteAllItems (hwndListView);

  // Initialize the columns in the list view.
  lvColumn.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
  lvColumn.fmt = LVCFMT_LEFT;
  lvColumn.cx = 120;

  // Insert the five columns in the list view.
  for (index = 0; index < 5; index++)
  {
    lvColumn.pszText = szString[index];
    ListView_InsertColumn (hwndListView, index, &lvColumn);
  }

  // Set the number of items in the list view to ITEM_COUNT.
  ListView_SetItemCount (hwndListView, ITEM_COUNT);

  return TRUE;
}

See Also

Creating a List View Control | Working with Common Controls

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.