CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    May 1999
    Posts
    37

    Help...annoyed beginner about to go postal

    i have posted on the forum for the past week and so far have not gotten any suggestions that work. all i need to do is get this **** list control to add items to the display and it refuses to do it. every time i add an item to it, it sets the item text to null(i.e. "").if i try to set the item text, it gives a debug assertion failure. Here below is the code for the SetItemText function of CListCtrl. It gives a debug assertion in this line:

    BOOL CListCtrl::SetItemText(int nItem, int nSubItem, LPCTSTR lpszText)
    {
    ASSERT(::IsWindow(m_hWnd));
    ASSERT((GetStyle() & LVS_OWNERDATA)==0); //This causes debug assertion failure(or at least thats what the debugger tells me
    LVITEM lvi;
    lvi.iSubItem = nSubItem;
    lvi.pszText = (LPTSTR) lpszText;
    return (BOOL) ::SendMessage(m_hWnd, LVM_SETITEMTEXT, nItem, (LPARAM)&lvi);
    }




    my list controls are initialized and accessed like this:

    CListCtrl m_listCtrl2; //this is in my header
    CListCtrl m_listCtrl; //this is in my header

    DDX_Control(pDX, IDC_LIST2, m_listCtrl2);//this is in DoDataExchange(...), it initializes it i think
    DDX_Control(pDX, IDC_LIST, m_listCtrl);//this is in DoDataExchange(...), it initializes it i think

    //These are in my OnInitDlg(...)
    m_listCtrl.InsertColumn(0, CString("Questions:"), LVCFMT_LEFT, bounds.Width(),0);
    m_listCtrl2.InsertColumn(0, CString("Answers:"), LVCFMT_LEFT, bounds.Width(),0);

    //this is how im adding to my List

    int i = m_listCtrl.GetItemCount(); //first time through returns 0
    m_listCtrl.InsertItem(i, dlg.m_textQ);//works as far as i can tell
    CString t = "Test"; //test string init
    t = m_listCtrl.GetItemText(1,0); //t's value goes from "Test" to ""
    m_listCtrl.SetItemText(i, 0, dlg.m_textQ); //must comment out to run(or i get debug assertion failure)
    i = m_listCtrl.GetItemCount(); //this returns 1 instead of 0 so i have added the item




    i have been working forever on this and any help would be great. i think that i have included all references to my CListCtrl variables so if you dont see something in here, it wasnt added by me to the code. so... HELP!!!

    thanks
    L5



  2. #2
    Join Date
    May 1999
    Posts
    37

    Re: Help...annoyed beginner about to go postal

    BTW, my list control is in report view mode.


  3. #3
    Guest

    Re: Help...annoyed beginner about to go postal

    This thing isn't a edit box where you can add text at your whim.

    Don't know what the dlg.m_TextQ for variable is but I suspect that it is a CString or a char*
    You need to use a LV_ITEM (or LVI_ITEM, don't have docs on hand atm)

    you need to set the mask of this item to LV_TEXT (or LVI_TEXT)
    then add the text to the item
    then insert the item


  4. #4
    Join Date
    May 1999
    Location
    TamilNadu, India
    Posts
    42

    Re: Help...annoyed beginner about to go postal

    In a listcontrol using ReportView mode, the first column in all the rows is the item which u can select rest is only for display if u don't use full row selection...
    If so, the first column, means 0 th column shd be added using InsertItem and not by using setItem text. U r trying to add like this for 0th column. SetItemText(i,0,CString). Try this and let me know...
    Thanks lot,
    Srini


  5. #5
    Join Date
    May 1999
    Posts
    116

    Re: Help...annoyed beginner about to go postal

    Check the settings for the control in th resource editor, and turn off OwnerDraw (cause this means that you will do the drawing). You only want that if you need something CListCtrl cant handle.


  6. #6
    Join Date
    May 1999
    Posts
    37

    Re: Help...annoyed beginner about to go postal

    that annoys me that i spent over week trying to figure it out and it was fixed by deselecting one little checkbox. thanks.


  7. #7
    Join Date
    May 1999
    Posts
    116

    Re: Help...annoyed beginner about to go postal

    Well the line it was asserting on, was trying to ensure that this style was turned off.
    When you get an assertion in the MFC code it is generally for a good reason. And if the assertion itsself does not provide some clues to the problem, debugging up to the assert should provide you with the asnwer (in most cases).


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