Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

List Box VC++

Hello All:

I am basically a fresher into VC++.

I have created a List Box in my Dialog.
Now, I want integers from 1 to 1000 to be displayed in my List Box.

So, I added a code to the OnitDialog() function [which is invoked just before the dialog box is displayed upon the execution of the function DoModal()]
as follows:

CListBox* pListBox2=static_cast<CListBox*>(GetDlgItem(IDC_LIST4_SECTIONWIDTH));

for (int i=1;i<=3000;i=i+1)
{

pListBox2->AddString("%d",i);

}

This is not working and giving me an error--
How could I make it work??
[632 byte] By [jerusalem] at [2007-11-11 10:08:33]
# 1 Re: List Box VC++
Addstring wants a string, you dont try to sent it printf args however. Try this:

char simple[20];
for(i = 0; i < 1000; i++)
{
sprintf(simple, "%d", i); //make a string fit to pass into addstring
pthing->AddString(simple);
}
jonnin at 2007-11-11 20:59:21 >