我测试了一个ListCtrl,有50行,10列,其中前2列是有值的,当我删除后8列后为什么Item不能选中了呢?

解决方案 »

  1.   

    BOOL CtempDlg::OnInitDialog()
    {
    CDialogEx::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range.
    ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
    ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE);
    if (pSysMenu != NULL)
    {
    BOOL bNameValid;
    CString strAboutMenu;
    bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
    ASSERT(bNameValid);
    if (!strAboutMenu.IsEmpty())
    {
    pSysMenu->AppendMenu(MF_SEPARATOR);
    pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
    }
    } // Set the icon for this dialog.  The framework does this automatically
    //  when the application's main window is not a dialog
    SetIcon(m_hIcon, TRUE); // Set big icon
    SetIcon(m_hIcon, FALSE); // Set small icon // TODO: Add extra initialization here
    m_list.ModifyStyle(0,LVS_REPORT|LVS_SINGLESEL);
    m_list.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES|LVS_EX_ONECLICKACTIVATE|LVS_EX_DOUBLEBUFFER); for (int i=0;i<10;i++)
    {
    m_list.InsertColumn(i,_T("hello"),LVCFMT_LEFT,50);
    }
    for (int i=0;i<50;i++)
    {
    m_list.InsertItem(i,_T("i"));
    m_list.SetItemText(i,1,_T("h"));
    } return TRUE;  // return TRUE  unless you set the focus to a control
    }
    void CtempDlg::OnBnClickedButton1()
    {
    CHeaderCtrl* pHead = m_list.GetHeaderCtrl();
    while (pHead->GetItemCount()>2)
    {
    pHead->DeleteItem(2);
    }
    }就这样,完了以后ListCtrl的Item没法选中了
      

  2.   

    CListCtrl::DeleteColumn
    BOOL DeleteColumn( int nCol );Return ValueNonzero if successful; otherwise zero.ParametersnColIndex of the column to be deleted.ResCall this function to delete a column from the list view control.