How do i get the number of items a itembox is carrying?
I tried

MessageBox::Show(listBox1->Items);

but no luck
Thanks in advanced.

Recommended Answers

All 11 Replies

What do you mean by "no luck"? Can you show us the error message?

My first guess is that I would image Show() takes a string, not a numeric value.

With no luck i mean that i dont have any idea how to do what i want to do and you are right that show() doesnt take a numeric value but even when i convert it to string i am not getting what i want.

My point was we can't help you get what you want if you don't tell us what that is! Are there compiler errors? Does the message box not show what you want it to?

Try this:

int a = 5;
MessageBox::Show(string(a)); // or however you were converting your number to a string

and this :

std::cout << "number of list box items: " << listBox1->Items << std::endl;

Once you get those working properly, you can try to combine them.

Ah now i understand your point,
i have a listitem box with 3 items(item1,item2 and item3) i want my messagebox to tell me that i have 3 items so when i use show() its suppose to tell me 3.

If you dont understand what i want tell me and ill try to explain better(my english is a little bad so pleas have patience with me)

Yes, I understand what you are trying to do - did you break it up into two parts like I suggested? Which part didn't work as you would expect?

converting a int to a string works but i am noticing that listBox1->Items isnt returning a number...
i really have no idea how to return the amounts of items i currently have in a listBox.

Well there is your problem. What is it returning? It is probably some actual object which contains the items. Is there a GetNumberOfItems() or similar function you should be using instead?

yeah its returning an object thing, i did not found any similar functions tho...

Is this a "visual studio" list box? (I'm not even sure of the terminology). Can you send a link to the documentation page of the list box? Surely there is a function to do this.

yes its a visual studio list box, after a more serious and very deep research i found the answer...
i had to use listBox1->Items->Count

thanks for your help man, i feel like a dorn tho cause the answer was infront of my face :P

No problem, glad it's working. I hope you see the process a little bit though - break up the problem into the absolute smallest pieces you can. Often that will lead exactly to the solution.

Please mark the thread as solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.