Announcement

Collapse
No announcement yet.

Add Array Content To ListBox, After Creation?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Add Array Content To ListBox, After Creation?

    With Control Add Listbox I can add the content of an array to the listbox at the time the listbox is created.

    But after that, I have to use a loop to add the contents of an array to the listbox.

    Is there a command I've missed that will let me add an entire array to the listobx - after I've created it?

    If the listbox is empty, I can delete it, then recreate it with the array inserted in just a line of code. But if it's not empty that won't work without recreating all of the entries.

    Granted, the loop is trivial - just 3 lines of code - but it seems like this would be a common enough task that there would be an existing function somewhere that does it for me.

    I didn't see anything at MSDN that would do it.

  • #2
    I guess this is where being able to program comes in real handy!!
    Rod
    I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

    Comment


    • #3
      Yes, I guess so.

      Sometimes, lazy is a great motivation to find a shorter/quicker way to do things. In this case, lazy loses, not-so-hard labor wins.

      Oh well ... until the next lazy spell hits me ...

      Comment


      • #4
        I don't think you can fill up a listbox or listview without a loop.
        I assume PB uses a loop as well.

        But these controls also allow you to use the existing array by simply set the number of items.
        Messages will tell you what entry of the array it needs and you must provide this data (on demand).

        This can speed up things and prevents you from using double amount of data during the fill.

        This is a specific style.
        hellobasic

        Comment


        • #5
          Why did that song, "I Have a New Feature Suggestion" suddenly start playing over and over in my head?
          Michael Mattias
          Tal Systems Inc. (retired)
          Racine WI USA
          [email protected]
          http://www.talsystems.com

          Comment


          • #6
            Suggested Message:

            Gentlemen;

            Please enhance the LISTBOX ADD statement to accept either a single string expression OR a string array. Suggested Syntax:
            Code:
            LISTBOX ADD hDlg, id&, StrExpr | StrArray()
            Suggested explanation to be added to help file:

            "If the StrArray() option is used, all elements of StrArray() are added to the current contents of the listbox following all current items; unless the listbox was created with style LBS_SORT, in which case all elements of StrArray() are added to the listbox's items in sorted order."
            Michael Mattias
            Tal Systems Inc. (retired)
            Racine WI USA
            [email protected]
            http://www.talsystems.com

            Comment


            • #7
              Sometimes, lazy is a great motivation to find a shorter/quicker way to do things. In this case, lazy loses, not-so-hard labor wins.
              A couple of years back I posted something to the effect that "Necessity is the Mother of invention, Laziness is the Father!"
              I'm wondering now why I don't have a MACRO for this. Just never thought of it, I guess.
              However, Michael's NFS is the way to go.
              Rod
              I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

              Comment


              • #8
                9 out of 10 i need a combination of text + param&
                So that rules out the simple array approach anyway.

                But since PB offers this on creation, a similar approach could be implemented.
                Even if it is text only.
                hellobasic

                Comment


                • #9
                  But since PB offers this on creation, a similar approach could be implemented.
                  Even if it is text only.
                  Where HAS imagination gone?
                  ===> Current support
                  Code:
                  LISTBOX SET USER hDlg, id&, item&, NumExpr
                  ===> New Support?
                  Code:
                  LISTBOX SET USER  hDlg, id&, NumArray()   ' new feature?
                  FWIW: I am not so sure I'd want to be 'catching' support calls when someone finds the "USER" values don't match because the listbox was created with style LB_SORT but the user forgot to sort NumArray() in the same order as the text strings. Come to think about it, I *KNOW* I would not want to be 'catching' support calls that day.

                  MCM
                  Michael Mattias
                  Tal Systems Inc. (retired)
                  Racine WI USA
                  [email protected]
                  http://www.talsystems.com

                  Comment


                  • #10
                    Or go deluxe......

                    Code:
                    LISTBOX Add hDlg, id&, StrExpr|StrArray()  [,USER  numExpr| numArray()]
                    MCM
                    Michael Mattias
                    Tal Systems Inc. (retired)
                    Racine WI USA
                    [email protected]
                    http://www.talsystems.com

                    Comment


                    • #11
                      Let's add one more option, the choice to append to, prepend to, or replace the existing LISTBOX contents.

                      Or maybe a different approach. Create your LISTBOX with a pointer to an array. Then do a LISTBOX REFRESH when you think it's needed. LISTVIEWs could have this, too. The sorting option could be made invalid (or just ignored); you would be responsible for doing the ARRAY SORT you want, if you even care about sorting.

                      Now, what if the listbox has more (or fewer) entries than the array? Maybe an option to specify the array subscript range you want. This might be good if you want to populate two boxes from one array (Names A-M, Names N-Z).
                      Erich Schulman (KT4VOL/KTN4CA)
                      Go Big Orange

                      Comment


                      • #12
                        >the choice to append to, prepend to, or replace the existing LISTBOX contents.

                        append LISTBOX ADD hDlg, id, StrArray () ' no LB_SORT style
                        Prepend LISTBOX INSERT hDlg, id, insertAtRow&, StrArray() ' NEW IDEA
                        Replace = LISTBOX RESET + LISTBOX ADD


                        >Create your LISTBOX with a pointer to an array. Then do a LISTBOX REFRESH when ..

                        That IMO is silly. Why maintain an array of the text strings when the control is already holding them? Better to go to a VIRTUAL listbox (LBS_NODATA + LB_SETCOUNT) if you want to maintain the data independent of the control.

                        Oh, heck....did I just fall for someone yanking my chain?

                        MCM
                        Michael Mattias
                        Tal Systems Inc. (retired)
                        Racine WI USA
                        [email protected]
                        http://www.talsystems.com

                        Comment


                        • #13
                          All I know is that I really, really enjoy planting a seed and watching it grow into a Sequoia right in front of my eyes! It's often educational beyond my meager expectations.

                          As a poor boy from Oklahoma I'm usually happy with a bologna sandwich. Here in the big city folks often feed me steak and I'm liking the diet!

                          Comment


                          • #14
                            >All I know is that I really, really enjoy planting a seed and watching it grow

                            See my comments here...

                            http://www.powerbasic.com/support/pb...29&postcount=5

                            MCM
                            Michael Mattias
                            Tal Systems Inc. (retired)
                            Racine WI USA
                            [email protected]
                            http://www.talsystems.com

                            Comment


                            • #15
                              Originally posted by Michael Mattias View Post
                              That IMO is silly. Why maintain an array of the text strings when the control is already holding them? Better to go to a VIRTUAL listbox (LBS_NODATA + LB_SETCOUNT) if you want to maintain the data independent of the control.

                              Oh, heck....did I just fall for someone yanking my chain?

                              MCM
                              If interacting with a .dll that you don't have source code for, passing an array to and/or from could be your only choice.

                              And I am not intentionally trying to provoke you to rage.
                              Erich Schulman (KT4VOL/KTN4CA)
                              Go Big Orange

                              Comment


                              • #16
                                If interacting with a .dll that you don't have source code for, passing an array to and/or from could be your only choice.
                                ???

                                I do not understand. If the data have been added to a 'regular' (non-virtual) listbox control, you can always get any or all 'elements' by retrieving the text from the control.

                                And if you are maintaining all the data in an array, why bother having the control store it, too? If the array changes, now you have to change the control, too; whereas if your control is 'virtual' you only have to worry about keeping the count correct.

                                That is, I like to think of a control being a lot like a thread-safe 'STATIC' variable... it holds values for you until you need 'em, and does so regardless of the number of window instances.


                                MCM
                                Michael Mattias
                                Tal Systems Inc. (retired)
                                Racine WI USA
                                [email protected]
                                http://www.talsystems.com

                                Comment

                                Working...
                                X