-
November 17th, 2008, 04:21 AM
#1
[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]
-
November 17th, 2008, 05:27 AM
#2
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.
-
November 17th, 2008, 06:07 AM
#3
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
-
November 17th, 2008, 06:39 AM
#4
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
-
November 17th, 2008, 07:33 AM
#5
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*.
-
November 17th, 2008, 08:49 AM
#6
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|