[RESOLVED] ListBox AddString() error
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: [RESOLVED] ListBox AddString() error

  1. #1
    Join Date
    May 2006
    Location
    beyond the pillars of hercules
    Posts
    295

    [RESOLVED] ListBox AddString() error

    i have created a listbox and a button to to add items to the listbox (MFC)
    i have added a variable (m_ctlListBox) to the listbox control
    but im getting an error, what im i doing wrong?

    Error message
    Code:
    error C2039: 'AddString' : is not a member of 'CListCtrl'
    1>        c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxcmn.h(258) : see declaration of 'CListCtrl'


    my code
    [code]
    CString strText;
    UpdateData();
    strText = m_txtListbox;
    UpdateData(FALSE);

    m_ctlListBox.AddString(strText);
    /[code]

  2. #2
    Join Date
    May 2002
    Posts
    1,435

    Re: ListBox AddString() error

    A CListCtrl generally has more than one column of text so AddString() is not used. Rows of text are referred to as 'Items.'

    You create a new row by calling InsertItem() with the row number and the text for the first column. If InsertItem() succeeded it will return the row number index which should be the same number you passed as a parameter.

    Now that you have created a row and inserted the first column of text you can fill the rest of the columns by calling SetItemText() with nItem=row and nSubItem=column.

    I am assuming that you have initially set-up your CListCtrl with the proper number of columns by calling InsertColumn() for each. There is no reason why you can't create a list control with a single column, but it that's what you want to maybe you should use CListBox which is similar but only has one column and an AddString() member.

  3. #3
    Join Date
    May 2006
    Location
    beyond the pillars of hercules
    Posts
    295

    Re: ListBox AddString() error

    thank that clears things out... i have edited my code but i get another error

    i have added this code on OnInitDialog()
    Code:
    	m_ctlListBox.InsertColumn(0, _T("Column 1"), LVCFMT_CENTER, 100);
    	m_ctlListBox.InsertColumn(1, _T("Column 2"), LVCFMT_LEFT, 100);
    	m_ctlListBox.InsertColumn(2, _T("Column 3"), LVCFMT_LEFT, 100);

    and on my button
    Code:
    	 CString strText;
             int nItem;
             UpdateData();
             strText = m_txtListbox;
             UpdateData(FALSE);
    	 
    
       nItem = m_ctlListBox.InsertItem(0,strText);
       m_ctlListBox.SetItemText(nItem,1,_T("Test"));

    and the error
    Code:
     
    1>ListBoxTut.obj : error LNK2019: unresolved external symbol "public: __thiscall CListBoxTutDlg::CListBoxTutDlg(class CWnd *)" (??0CListBoxTutDlg@@QAE@PAVCWnd@@@Z) referenced in function "public: virtual int __thiscall CListBoxTutApp::InitInstance(void)" (?InitInstance@CListBoxTutApp@@UAEHXZ)
    
    1> fatal error LNK1120: 1 unresolved externals

  4. #4
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,273

    Re: ListBox AddString() error

    The error has nothing to do with the code you have posted. It sounds like your do NOT have the implementation of this dialog ctor:
    Code:
    CListBoxTutDlg::CListBoxTutDlg(class CWnd *)
    Victor Nijegorodov

  5. #5
    Join Date
    May 2002
    Posts
    1,435

    Re: ListBox AddString() error

    There are typically two reasons for an error like this.

    (1) You have not included CListBoxTutDlg.cpp in your project.

    (2) You have not implemented a constructor for CListBoxTutDlg that takes a CWnd*.

  6. #6
    Join Date
    May 2006
    Location
    beyond the pillars of hercules
    Posts
    295

    Re: ListBox AddString() error

    thank you! ive fixed the problem!

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center