zoukankan      html  css  js  c++  java
  • 列表控件学习1

    一、设置列表样式

    设置当前的列表视图控件扩展的样式

    CListCtrl::SetExtendedStyle

    函数原型

    DWORDSetExtendedStyle(DWORD dwNewStyle);

    dwNewStyle

    要使用列表视图控件的扩展样式的组合。

    ConstantDescription
    LVS_EX_AUTOAUTOARRANGE

    Windows Vista.如果没有图标自动排列图标位置设置(类似于LVS_AUTOARRANGE)。

    LVS_EX_AUTOCHECKSELECT Windows Vista. 自动选择单击复选框
    LVS_EX_AUTOSIZECOLUMNS

    Windows Vista.自动大小列表视图列。

    LVS_EX_BORDERSELECT

    Version 4.71.边框颜色变化时选择一个项目,而不是突出显示项。

    LVS_EX_CHECKBOXES

    每一行最前面都有一个复选框

    LVS_EX_COLUMNOVERFLOW

    Indicates that an overflow button should be displayed in icon/tile view if there is not enough client width to display the complete set of header items. The list-view control sends the LVN_COLUMNOVERFLOWCLICK notification when the overflow button is clicked. This flag is only valid when LVS_EX_HEADERINALLVIEWS is also specified.

    LVS_EX_COLUMNSNAPPOINTS

    Windows Vista. Snap to minimum column width when the user resizes a column.

    LVS_EX_DOUBLEBUFFER

    Version 6.00. Paints via double-buffering, which reduces flicker. This extended style also enables alpha-blended marquee selection on systems where it is supported.

    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 theFlat Scroll Bar APIs. If the system metrics change, you are responsible for adjusting the scroll bar metrics withFlatSB_SetScrollProp. SeeFlat Scroll Barsfor further details.

    LVS_EX_FULLROWSELECT

    整行选中

    LVS_EX_GRIDLINES

    网格线

    LVS_EX_HEADERDRAGDROP

    列表头/列标题名可以拖动

    LVS_EX_HEADERINALLVIEWS

    Windows Vista. Show column headers in all view modes.

    LVS_EX_HIDELABELS

    Version 6.00. Hides the labels in icon and small icon view.

    LVS_EX_INFOTIP

    Version 4.71. When a list-view control uses theLVS_EX_INFOTIPstyle, theLVN_GETINFOTIPnotification code is sent to the parent window before displaying an item's tooltip.

    LVS_EX_JUSTIFYCOLUMNS

    Windows Vista. Icons are lined up in columns that use up the whole view.

    LVS_EX_LABELTIP

    Version 5.80. If a partially hidden label in any list view mode lacks tooltip text, the list-view control will unfold the label. If this style is not set, the list-view control will unfold partly hidden labels only for the large icon mode.

    LVS_EX_MULTIWORKAREAS

    Version 4.71. If the list-view control has theLVS_AUTOARRANGEstyle, the control will not autoarrange its icons until one or more work areas are defined (seeLVM_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 anLVN_ITEMACTIVATEnotification code to the parent window when the user clicks an item. This style also enableshot trackingin the list-view control. Hot tracking means that when the cursor moves over an item, it is highlighted but not selected. See the Extended List-View Styles Remarks section for a discussion of item activation.

    LVS_EX_REGIONAL

    Version 4.71through Version 5.80 only. Not supported on Windows Vista. Sets the list view window region to include only the item icons and text usingSetWindowRgn. Any area that is not part of an item is excluded from the window region. This style is only available to list-view controls that use theLVS_ICONstyle.

    LVS_EX_SIMPLESELECT

    Version 6.00. In icon view, moves the state image of the control to the top right of the large icon rendering. In views other than icon view there is no change. When the user changes the state by using the space bar, all selected items cycle over, not the item with the focus.

    LVS_EX_SINGLEROW

    Version 6.00. Not used.

    LVS_EX_SNAPTOGRID

    Version 6.00. In icon view, icons automatically snap into a grid.

    LVS_EX_SUBITEMIMAGES

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

    LVS_EX_TRACKSELECT

    Version 4.70. Enables hot-track selection in a list-view control. Hot 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 aLVM_SETHOVERTIMEmessage. This style applies to all styles of list-view control. You can check whether hot-track selection is enabled by callingSystemParametersInfo.

    LVS_EX_TRANSPARENTBKGND

    Windows Vista. Background is painted by the parent viaWM_PRINTCLIENT.

    LVS_EX_TRANSPARENTSHADOWTEXT

    Windows Vista. Enable shadow text on transparent backgrounds only.

    LVS_EX_TWOCLICKACTIVATE

    Version 4.70. The list-view control sends anLVN_ITEMACTIVATEnotification code to the parent window when the user double-clicks an item. This style also enableshot trackingin the list-view control. Hot tracking means that when the cursor moves over an item, it is highlighted but not selected. See the Extended List-View Styles Remarks section for a discussion of item activation.

    LVS_EX_UNDERLINECOLD

    Version 4.71. Causes those non-hot items that may be activated to be displayed with underlined text. This style requires thatLVS_EX_TWOCLICKACTIVATEbe set also. See the Extended List-View Styles Remarks section for a discussion of item activation.

    LVS_EX_UNDERLINEHOT

    Version 4.71. Causes those hot items that may be activated to be displayed with underlined text. This style requires thatLVS_EX_ONECLICKACTIVATEorLVS_EX_TWOCLICKACTIVATEalso be set. See the Extended List-View Styles Remarks section for a discussion of item activation.

    例子:

    m_list.SetExtendedStyle(LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT); 

    LVS_EX_FULLROWSELECT选择一行时整行高亮显示,不设置默认只是该行第一列高亮显示.

    二、设置列标题

    CListCtrl::InsertColumn

     

    函数原型

    int InsertColumn( int nCol, const LVCOLUMN* pColumn );

     

    int InsertColumn( int nCol, LPCTSTR lpszColumnHeading, int nFormat = LVCFMT_LEFT, int nWidth = -1, int nSubItem = -1 );

    nCol表示要插入列的列号。

    pColumn 为新建列属性的LVCOLUMN结构的地址。

    对于第二种函数重载,参数lpszcolumnHeading 为列标题的字符串的地址,所以可以使用一个字符串,比如 "姓名"。

    nFormat 指定列对齐方式的整数,缺省值是左对齐。它可以为下列值之一:LVCFMT_LEFT,LVCFMT_RIGHT或LVCFMT_CENTER。

    nWidth 以像素为单位的列宽。缺省值为-1,表示没有设置列宽。

    nSubItem 与列相关联的子项的索引。缺省值为-1,表示没有子项与列相关。

    例子:

    m_list.InsertColumn(0,"序号",LVCFMT_CENTER,60);
    m_list.InsertColumn(1,"姓名",LVCFMT_CENTER,60);
    m_list.InsertColumn(2,"学号",LVCFMT_CENTER,60);
    m_list.InsertColumn(3,"专业",LVCFMT_CENTER,60);

    LVCFMT_CENTER代表文字显示居中 60代表宽度

    m_list.SetColumnWidth(1,80);   //修改列的宽度

    m_list.SetColumnWidth(2,LVSCW_AUTOSIZE_USEHEADER); //根据列内容自动调整宽度

    三、插入行

    CListCtrl::InsertItem

    函数原型

    int InsertItem( const LVITEM* pItem );

    int InsertItem( int nItem, LPCTSTR lpszItem );

    int InsertItem( int nItem, LPCTSTR lpszItem, int nImage );

    int InsertItem( UINT nMask, int nItem, LPCTSTR lpszItem, UINT nState, UINT nStateMask, int nImage, LPARAM lParam );

    CListCtrl::SetItemText

    BOOL SetItemText( int nItem, int nSubItem, LPTSTR lpszText );

    Return Value

    Nonzero if successful; otherwise zero.

    Parameters

    nItem

    Index of the item whose text is to be set.

    nSubItem

    Index of the subitem, or zero to set the item label.

    lpszText

    Pointer to a string that contains the new item text.

    第一列用InsertItem插入

    m_list.InsertItem(0,"1");
    m_list.InsertItem(1,"2");
    m_list.InsertItem(2,"3");

    其他列用SetItemText插入

    m_list.SetItemText(0,1,"张三");
    m_list.SetItemText(0,2,"20180101");
    m_list.SetItemText(0,3,"通信工程");

    这样就可以完成列表的制作了

     删除数据

    m_list.DeleteAllItems();//删除所有数据
    m_list.DeleteColumn(0);//删除指定列 这里删第一列
    m_list.DeleteItem(1);//删除指定行的数据

  • 相关阅读:
    appium之adb常用命令
    测试基础之等价类
    selenium之CSS定位
    括号序列的最小代价
    Spark相对于MapReduce的优势
    Cache系统设计
    [京东2017实习生笔试] 终结者C
    [京东2017实习生笔试] 通过考试
    [hihoCoder] 1078. 线段树的区间修改
    [转载] 一步一步理解线段树
  • 原文地址:https://www.cnblogs.com/qiwu1314/p/8473501.html
Copyright © 2011-2022 走看看