我现在在一对话框中加入一个CListCtrl的控件,当向ListCtrl控件中加入多个Item时出现滚动条,现在我想提供一个查找功能,请问如何定位垂直滚动条到找到子项的位置。
   我想用m_ListCtrl.SetScrollPos(SB_VERT,nPos)来实现,此时滚动条是移动了,但ListCtrl中的内容并没有移动,再手工移动滚动条时上面出现一片白色,请教如何实现滚动条与ListCtrl的内容一致移动;

解决方案 »

  1.   

    MSDN:
    Unless the LVS_NOSCROLL window style is specified, a list-view control can be scrolled to show more items than can fit in the client area of the control. You can retrieve a list-view control's scroll position and related information, scroll a list-view control by a specified amount, or scroll a list-view control so that a specified list item is visible. In icon view or small icon view, the current scroll position is defined by the view origin. The view origin is the set of coordinates, relative to the visible area of the list-view control, that correspond to the view coordinates (0, 0). To retrieve the current view origin, use the LVM_GETORIGIN message. This message should be used only in icon or small icon view; it returns an error in list or report view. In list or report view, the current scroll position is defined by the top index. The top index is the index of the first visible item in the list-view control. To retrieve the current top index, use the LVM_GETTOPINDEX message. This message returns a valid result only in list or report view; it returns zero in icon or small icon view. You can use the LVM_GETVIEWRECT message to retrieve the bounding rectangle of all items in a list-view control, relative to the visible area of the control. The LVM_GETCOUNTPERPAGE message returns the number of items that fit in one page of the list-view control. This message returns a valid result only in list and report views; in icon and small icon views, it returns the total number of items. To scroll a list-view control by a specific amount, use the LVM_SCROLL message. Using the LVM_ENSUREVISIBLE message, you can scroll the list-view control, if necessary, to ensure that a specified item is visible. 
      

  2.   

    试试这些代码:
    m_ctlLC.SetItem(nIndex, 0, LVIF_STATE, NULL, 0, LVIS_SELECTED, 0)
    m_ctlLC.SetFocus();
      

  3.   

    and  add style: show selection always