Fill Listbox

This is a discussion on Fill Listbox within the Windows Programming forums, part of the Platform Specific Boards category; Id like to fill a listbox (BC++ 6) with the numbers 0 to n; Its a graphical user interface and ...

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    7

    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
    Last edited by Xentor; 09-24-2006 at 03:46 AM.

  2. #2
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    This doesn't seem to be Win32 API, what is it? A wrapper?
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    7
    I think its a wrapper, but just tell me
    how do i increment the listbox position so i can write multiple lines.

  4. #4
    Registered User
    Join Date
    Aug 2006
    Posts
    74
    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)
    Last edited by Kurisu33; 09-24-2006 at 04:02 AM.

  5. #5
    Registered User
    Join Date
    Aug 2006
    Posts
    74
    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.
    Last edited by Kurisu33; 09-24-2006 at 04:09 AM.

  6. #6
    Registered User
    Join Date
    Sep 2006
    Posts
    7
    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.

  7. #7
    Registered User
    Join Date
    Aug 2006
    Posts
    74
    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");
    Last edited by Kurisu33; 09-24-2006 at 04:36 AM.

  8. #8
    Registered User
    Join Date
    Sep 2006
    Posts
    7
    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
    Last edited by Xentor; 09-24-2006 at 04:41 AM.

  9. #9
    Registered User
    Join Date
    Aug 2006
    Posts
    74
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. ListBox Extra Data Storage
    By Welder in forum Windows Programming
    Replies: 1
    Last Post: 11-01-2007, 02:46 PM
  2. Replies: 3
    Last Post: 12-22-2004, 07:29 PM
  3. cant load dialog with listbox, help
    By terracota in forum Windows Programming
    Replies: 2
    Last Post: 11-22-2004, 07:11 PM
  4. How to cast a ListBox item to an int for a switch statment?
    By Swaine777 in forum C++ Programming
    Replies: 8
    Last Post: 09-26-2004, 09:52 PM
  5. Getting FULL filename from listbox
    By Garfield in forum Windows Programming
    Replies: 8
    Last Post: 01-27-2002, 08:28 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21