CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: CListCtrl HELL.

  1. #1
    Join Date
    May 1999
    Posts
    37

    CListCtrl HELL.

    i am very severely annoyed right now. all that i want to do is insert a freakin item into a freakin listCtrl without so much freakin trouble.

    this is the function that im usin to add items to my listCtrl boxes(i added controls through VC++ 6 to my list controls and they are of type CListCtrl):


    CAddRecDlg dlg;
    int result = dlg.DoModal();
    UpdateData();
    if(result == IDOK && dlg.m_textQ.GetLength() != 0 && dlg.m_textA.GetLength() != 0)
    {
    int i = m_listCtrl.GetItemCount();
    tNode* tmp;
    tmp = SelectNode(m_treeCtrl.GetSelectedItem());
    tmp->Q.resize(tmp->Q.length() + 1);
    tmp->A.resize(tmp->A.length() + 1);
    tmp->Q[tmp->Q.length() - 1] = dlg.m_textQ;
    tmp->A[tmp->A.length() - 1] = dlg.m_textA;
    m_listCtrl.InsertItem(i, dlg.m_textA);
    CString t = m_listCtrl.GetItemText(i,0); //this always returns a null string
    m_listCtrl2.InsertItem(i, dlg.m_textA);

    m_listCtrl.SetItemText(i,0,"Test"); //always gives debug assertion failure and i comment out to get it to run
    //

    }
    }



    tNode is simple a structure that i created and has nothing to do with the listCtrl

    this is how my lists are initialized(with OnInitDlg() ):


    CDialog::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)
    {
    CString strAboutMenu;
    strAboutMenu.LoadString(IDS_ABOUTBOX);
    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

    if(!myRoot.NodeName) //Lists are initialized here:
    {
    CRect bounds;
    m_listCtrl.GetWindowRect(bounds);
    myRoot.NodeName = m_treeCtrl.InsertItem(CString("MyList"));
    m_treeCtrl.SelectItem(myRoot.NodeName);
    m_listCtrl.InsertColumn(0, CString("Questions:"), LVCFMT_LEFT, bounds.Width(),0);
    m_listCtrl2.InsertColumn(0, CString("Answers:"), LVCFMT_LEFT, bounds.Width(),0);
    Invalidate();
    }

    // TODO: Add extra initialization here

    return TRUE; // return TRUE unless you set the focus to a control
    }




    as you can see, ive added columns and everything
    but every time i try to run(in report view... i can get it to run in list view mode but it still doesnt add anything) it gives me a debug assertion failure.

    the set item text always flags a debug assertion failure and if i let it run through to system dll's it gives me one also. can someone plz help me?

    thanks for the time
    L5




  2. #2
    Join Date
    May 1999
    Location
    Sydney, Australia
    Posts
    420

    Re: CListCtrl HELL.

    Try this:


    const int ind = m_listCtrl.InsertItem(i, dlg.m_textA);
    CString t = m_listCtrl.GetItemText(ind,0); //this always returns a null string
    m_listCtrl.SetItemText(ind,0,"Test"); //always gives debug assertion failure and i comment out to get it to run




    Sally


  3. #3
    Join Date
    May 1999
    Posts
    128

    Re: CListCtrl HELL.

    m_listCtrl.SetItemText(i,0,"Test");

    this line will definitely cause you grief cause 'i' is the count of items in the control, which +1 above last index (item indexes are zero based).



  4. #4
    Join Date
    May 1999
    Posts
    128

    Re: CListCtrl HELL.

    sorry, wasn't paying attention. i just noticed the InsertItem call you have preceding SetItemText.

    What exactly does SetItemText assert on, i.e. what's mfc complaining about?



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured