denfor Posted January 4, 2005 Posted January 4, 2005 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. :( Quote
Administrators PlausiblyDamp Posted January 4, 2005 Administrators Posted January 4, 2005 When you say does not work how exactly is it failing? Are you getting errors or is it just not producing the correct output? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
AlexCode Posted January 4, 2005 Posted January 4, 2005 hummmm... Are you trying to add rows (items) to the ListBox control like: 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 ? Quote Software bugs are impossible to detect by anybody except the end user.
denfor Posted January 5, 2005 Author Posted January 5, 2005 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 Quote
AlexCode Posted January 5, 2005 Posted January 5, 2005 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: : System::String* __tempString__ = "you have " + a.ToString() + " problems"; Then add this tempString to the ListBox with the Items.Add... It should work... Alex Quote Software bugs are impossible to detect by anybody except the end user.
denfor Posted January 5, 2005 Author Posted January 5, 2005 :( :( 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? Quote
AlexCode Posted January 5, 2005 Posted January 5, 2005 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... System::String* __tempString__ = __tempString__->Concat("you have ", a.ToString(), " problems"); this->listBox1->Items->Add(__tempString__); Alex Quote Software bugs are impossible to detect by anybody except the end user.
Wile Posted January 5, 2005 Posted January 5, 2005 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. Quote Nothing is as illusive as 'the last bug'.
denfor Posted January 5, 2005 Author Posted January 5, 2005 thank u alex!.it solved my problem. have a nice day,but get ready ,i will probably come with more questions next time :D Quote
AlexCode Posted January 5, 2005 Posted January 5, 2005 I believe that, what you just proposed, was quite his last try... Quote Software bugs are impossible to detect by anybody except the end user.
AlexCode Posted January 5, 2005 Posted January 5, 2005 thank u alex!.it solved my problem. have a nice day,but get ready ,i will probably come with more questions next time :D Shoot them... don't be sorry for me!!! :D:D:D Alex :p Quote Software bugs are impossible to detect by anybody except the end user.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.