listboxn ?

denfor

Newcomer
Joined
Dec 21, 2004
Messages
11
hello,
i use visual c++.NET 2003.i just wanna know how can i write words and numbers in one row of the list box? for example a find "a" in code.a=1,a=2,a=3 for different cases.i want to see in ONE ROW of the listbox;

row1: you have 1 problem
row2: you have 2 problem
row3 : you have 3 problem
.
.
.
in the code
__mcTemp__1[0] ="you have "+a.ToString()+" problems";
does not work.

please help me. :(
 
hummmm...
Are you trying to add rows (items) to the ListBox control like:
C#:
LBox[0] ="you have "+a.ToString()+" problems";
??

What exactly id the __mcTemp__1[0] ??
An array of String or the actrual ListBox?

What is this?
for example a find "a" in code.a=1,a=2,a=3 for different cases.
An ENUMERATION ?
 
my actual code is ;

System::Object* __mcTemp__1[] = new System::Object*[1];

__mcTemp__1[0] =? ? ?

this->listBox1->Items->AddRange(__mcTemp__1);

i know how to add rows to the listbox.but i need some code to show text and numbers in one row.numbers are found in each button push,so they r not constant.when some one enters some numbers in the textbox and pushes the "calculate" button ,code does some calculations and shows the result in Listbox.but i need someting to write each number and a text in ONE ROW.how can i do it?


the error i have for :

__mcTemp__1[0] ="you have"+ a.ToString()+" problems";

is

error C2110: '+' : cannot add two pointers

.thank u for your considerations.i hope someone knows how to solve this
 
It's allways peasant to see some VC code... :rolleyes:

Try to make the String you want before adding it to the ListBox, this way you'll see if the problem is the ListBox or the concatenation of the text...

Something like this... I think :eek: :
Code:
System::String* __tempString__ = "you have " + a.ToString() + " problems";

Then add this tempString to the ListBox with the Items.Add...
It should work...

Alex
 
:(
:(
i just tried your way as;

System::String* __tempString__ = "you have " + a.ToString() + " problems";
this->listBox1->Items->Add(__tempString__);

but i still have the same error as:
error C2110: '+' : cannot add two pointers

any ideas?
 
You have a concatenation problem... probably + signal doesn't represent a concatenate instruction in VC...

I don't know much of VC but, considering the same framework base, on the String variable you should have a Concat Method that should work you out...

Something like the following...
Code:
System::String* __tempString__ = __tempString__->Concat("you have ", a.ToString(), " problems");
this->listBox1->Items->Add(__tempString__);

Alex
 
Havent worked with C++ in VS.net yet, but maybe if you create a string on the fly with quotes (the "you have" for example) it probably doesnt create a System::String object, but a char array or something like that (I admit, been over a year that I last did work in C++ ;) )

If the System::String doesnt have an overload to operator + to add a char array (or whatever is created), it probably tries to add it as a pointer like the errror says.

Try storing everything in separate System::String objects first before adding them.
So
System::String youHaveText = "You have";
and later use that System::String object like:
System::String newText = youHaveText + a.ToString();

Now you are sure to use System::String objects and the correct operator + overload.
 
thank u alex!.it solved my problem.
have a nice day,but get ready ,i will probably come with more questions next time :D
 
Back
Top