我在对话框上拉了个listbox控件,但不知道怎么改变它的排序方法。在msdn上好像只有在create的时候可以设定,我改怎么办?

解决方案 »

  1.   

    ResourceView中,在ListBox上单击右键,属性--〉Style 选中Sort属性
      

  2.   

    virtual int CompareItem( LPCOMPAREITEMSTRUCT lpCompareItemStruct );
    If you create an owner-draw list box with the LBS_SORT style, you must override this member function to assist the framework in sorting new items added to the list box.
    Example// CMyListBox is my owner-drawn list box derived from CListBox. This 
    // example compares two items using strcmp to sort items in reverse 
    // alphabetical order. The list box control was created with the 
    // following code:
    //   pmyListBox->Create(
    //      WS_CHILD|WS_VISIBLE|WS_BORDER|WS_HSCROLL|WS_VSCROLL|
    //      LBS_SORT|LBS_MULTIPLESEL|LBS_OWNERDRAWVARIABLE,
    //      myRect, pParentWnd, 1);
    //
    int CMyListBox::CompareItem(LPCOMPAREITEMSTRUCT lpCompareItemStruct) 
    {
       ASSERT(lpCompareItemStruct->CtlType == ODT_LISTBOX);
       LPCTSTR lpszText1 = (LPCTSTR) lpCompareItemStruct->itemData1;
       ASSERT(lpszText1 != NULL);
       LPCTSTR lpszText2 = (LPCTSTR) lpCompareItemStruct->itemData2;
       ASSERT(lpszText2 != NULL);   return strcmp(lpszText2, lpszText1);
    }
      

  3.   

    在ListBox上单击右键,properties -〉Style ,选中Sort