-
Fill Listbox
Id like to fill a listbox (BC++ 6) with the numbers 0 to n;
Its a graphical user interface and i cant seem to get it to work.
From what i figured out: ->Items->Add(i) adds a string i to the listbox but it doesnt wanna add more then 1.
I tried: something like this (pseudo code)
for(i=0; i <= n; i++)
Items->Add(i)
now im wondering how i can extend it to make it add more then jst one number.
ANyone have any clues??
Its a wrapper
-
This doesn't seem to be Win32 API, what is it? A wrapper?
-
I think its a wrapper, but just tell me
how do i increment the listbox position so i can write multiple lines.
-
Been ages since I used Borland to create a Win app.. wish I could help, but all is forgotten. I got an old book lying around though and will browse through it to see if I can see the solution.
(I think they call it the Visual Component Library)
-
Just quickly, you are only trying to add STRINGS right? The listbox only seems to like strings so your logic should work.
Code:
Listing->Items->Add("Item 1");
Listing->Items->Add("Item 2");
Listing->Items->Add("Item 3");
Listing->Items->Add("Item 4");
Listing->Items->Insert(4, "Item 5");
??
If you are trying to add #'s perhaps there is a way to convert it to a string first?
Code:
pseudocode
for(int i = 0; i < n; i++)
Listing->Items->Add(convertToString(i)); // Pseudocode not actual code.
-
For some reason the increment doesnt work, as it only adds one line. Namely where i<=n.
Iff i add them manually like add("a"); add("b") it works fine. But if i use the itterator to add each time it doesnt work.
Is there something to increment the position in a listbox or something similar.
Im really stuck here.
The std cout function works fine like that. But this whole VCL is doing my head in.
-
so:
Code:
for(int i = 0; i < 5; i++)
Listing->Items->Add("a");
So when you do the above in your code it isn't adding 5 a's to your listbox?
Also, there appears to be an insert function:
Insert(param1, param2);
Where
param1 = position into the listbox where 0 = first item, 1 = second, etc..
param2 = string to add.
Code:
for(int i = 0; i < 5; i++)
Listing->Items->Insert(i, "a");
-
It does work???
for(int i = 0; i < teller; i++)
this->ListBox1->Items->Add(i);
adds the number from 0 to teller
still dunno where i went wrong.
Tnx a llot
-
yep, no problem.
As for your original problem the only thing I can think of is possibly a pesky semicolon at the end of your loop statement.
Ex:
Code:
for(int i = 0; i < 5; i++); <---- Would cause an empty loop to execute 5 times.
this->ListBox1->Items->Add(i); <---- After the loop ends this statement is only executed once.