|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Add an Item to a ListBoxIs it possible to add an item to a list box so the last entered item would be the first on the list or at a position of my choice, for example: List1.AddItem "1" List1.AddItem "2" List1.AddItem "3" .... would give you 1, 2, 3 in your list. How can I make it 3, 2, 1 when the AddItem method has be done in a specific order. Is the only way to create an array and feed the array values into the List in reverse order? This is not the best way since there are many actions the program undertakes and these are added to the list box and I want the user to see 'real time' what the progress is on these issues. Any one list can have up to 50 - 60 actions. For purely aesthetics I would rather not have a list box the full height of the form. What is the best way of trying to achieve this or is there another way to approach this task? Thanks again. Alastair MacFarlane
Show quote
Hide quote
"Alastair MacFarlane" <anonym***@microsoft.com> wrote in message Did you bother to read VB's Help on the AddItem method? There's an optional news:OoaP7cFQGHA.4952@TK2MSFTNGP09.phx.gbl... > Dear All, > > Is it possible to add an item to a list box so the last entered item would > be the first on the list or at a position of my choice, for example: > > List1.AddItem "1" > List1.AddItem "2" > List1.AddItem "3" > > ... would give you 1, 2, 3 in your list. How can I make it 3, 2, 1 when > the AddItem method has be done in a specific order. Is the only way to > create an array and feed the array values into the List in reverse order? Index argument you can specify to add an item at any given position (assuming it's a valid position). Note that the Sorted property must be False. This will do what you want: List1.AddItem "1", 0 List1.AddItem "2", 0 List1.AddItem "3", 0 Basically, you're just adding each item as the first item. -- Mike Microsoft MVP Visual Basic Thanks MikeD,
I never realised there was another parameter after the item to be added. It never appears in a drop down list for this method. Why not MikeD? Is 0 the only value that can be added? If I try to say 1, I get an error. This will do and I appreciate your help. I would like the first Item on the list always to stay the same, for example "Loading progress...". This is not that important. I appreciate your speedy reply and help. Alastair MacFarlane Show quoteHide quote "MikeD" <nob***@nowhere.edu> wrote in message news:egN58wFQGHA.1040@TK2MSFTNGP12.phx.gbl... > > "Alastair MacFarlane" <anonym***@microsoft.com> wrote in message > news:OoaP7cFQGHA.4952@TK2MSFTNGP09.phx.gbl... >> Dear All, >> >> Is it possible to add an item to a list box so the last entered item >> would be the first on the list or at a position of my choice, for >> example: >> >> List1.AddItem "1" >> List1.AddItem "2" >> List1.AddItem "3" >> >> ... would give you 1, 2, 3 in your list. How can I make it 3, 2, 1 when >> the AddItem method has be done in a specific order. Is the only way to >> create an array and feed the array values into the List in reverse order? > > Did you bother to read VB's Help on the AddItem method? There's an > optional Index argument you can specify to add an item at any given > position (assuming it's a valid position). Note that the Sorted property > must be False. This will do what you want: > > List1.AddItem "1", 0 > List1.AddItem "2", 0 > List1.AddItem "3", 0 > > Basically, you're just adding each item as the first item. > > -- > Mike > Microsoft MVP Visual Basic > > When I type in List1.AddItem and a space, I see this as a tooltip in the
code window AddItem(Item As String,[Index]) The square brackets tell you this is a optional argument. Also, if you place your cursor over AddItem and press Shift-F2 you will see the same info in the Object Browser. Show quoteHide quote "Alastair MacFarlane" <anonym***@microsoft.com> wrote in message news:OkQkyDGQGHA.4952@TK2MSFTNGP09.phx.gbl... > Thanks MikeD, > > I never realised there was another parameter after the item to be added. It > never appears in a drop down list for this method. Why not MikeD? Is 0 the > only value that can be added? If I try to say 1, I get an error. This will > do and I appreciate your help. > > I would like the first Item on the list always to stay the same, for example > "Loading progress...". This is not that important. > > I appreciate your speedy reply and help. > > Alastair MacFarlane > > "MikeD" <nob***@nowhere.edu> wrote in message > news:egN58wFQGHA.1040@TK2MSFTNGP12.phx.gbl... > > > > "Alastair MacFarlane" <anonym***@microsoft.com> wrote in message > > news:OoaP7cFQGHA.4952@TK2MSFTNGP09.phx.gbl... > >> Dear All, > >> > >> Is it possible to add an item to a list box so the last entered item > >> would be the first on the list or at a position of my choice, for > >> example: > >> > >> List1.AddItem "1" > >> List1.AddItem "2" > >> List1.AddItem "3" > >> > >> ... would give you 1, 2, 3 in your list. How can I make it 3, 2, 1 when > >> the AddItem method has be done in a specific order. Is the only way to > >> create an array and feed the array values into the List in reverse order? > > > > Did you bother to read VB's Help on the AddItem method? There's an > > optional Index argument you can specify to add an item at any given > > position (assuming it's a valid position). Note that the Sorted property > > must be False. This will do what you want: > > > > List1.AddItem "1", 0 > > List1.AddItem "2", 0 > > List1.AddItem "3", 0 > > > > Basically, you're just adding each item as the first item. > > > > -- > > Mike > > Microsoft MVP Visual Basic > > > > > > Norm,
Thanks for that. Forgive this chap his stupid Sunday afternoon ramblings, but I was declaring the ListBox as Object so I wouldn't in this instance see the drop down list (for this I apologise as I should've mentioned it) and from my observations in the past, I have never noticed the optional [Index] parameter. Does it only allow 0 as the value for this Index? Thanks again. Alastair MacFarlane Show quoteHide quote "Norm Cook" <normcookNOSPAM@cableone.net> wrote in message news:120lvdr7eg0r128@corp.supernews.com... > When I type in List1.AddItem and a space, I see this as a tooltip in the > code window > AddItem(Item As String,[Index]) > The square brackets tell you this is a optional argument. > Also, if you place your cursor over AddItem and press Shift-F2 > you will see the same info in the Object Browser. > > "Alastair MacFarlane" <anonym***@microsoft.com> wrote in message > news:OkQkyDGQGHA.4952@TK2MSFTNGP09.phx.gbl... >> Thanks MikeD, >> >> I never realised there was another parameter after the item to be added. > It >> never appears in a drop down list for this method. Why not MikeD? Is 0 >> the >> only value that can be added? If I try to say 1, I get an error. This >> will >> do and I appreciate your help. >> >> I would like the first Item on the list always to stay the same, for > example >> "Loading progress...". This is not that important. >> >> I appreciate your speedy reply and help. >> >> Alastair MacFarlane >> >> "MikeD" <nob***@nowhere.edu> wrote in message >> news:egN58wFQGHA.1040@TK2MSFTNGP12.phx.gbl... >> > >> > "Alastair MacFarlane" <anonym***@microsoft.com> wrote in message >> > news:OoaP7cFQGHA.4952@TK2MSFTNGP09.phx.gbl... >> >> Dear All, >> >> >> >> Is it possible to add an item to a list box so the last entered item >> >> would be the first on the list or at a position of my choice, for >> >> example: >> >> >> >> List1.AddItem "1" >> >> List1.AddItem "2" >> >> List1.AddItem "3" >> >> >> >> ... would give you 1, 2, 3 in your list. How can I make it 3, 2, 1 >> >> when >> >> the AddItem method has be done in a specific order. Is the only way to >> >> create an array and feed the array values into the List in reverse > order? >> > >> > Did you bother to read VB's Help on the AddItem method? There's an >> > optional Index argument you can specify to add an item at any given >> > position (assuming it's a valid position). Note that the Sorted >> > property >> > must be False. This will do what you want: >> > >> > List1.AddItem "1", 0 >> > List1.AddItem "2", 0 >> > List1.AddItem "3", 0 >> > >> > Basically, you're just adding each item as the first item. >> > >> > -- >> > Mike >> > Microsoft MVP Visual Basic >> > >> > >> >> > > "Alastair MacFarlane" <anonym***@microsoft.com> wrote in message You REALLY need to read VB's Help. Everything you've asked could have been news:eLaKmrGQGHA.1096@TK2MSFTNGP11.phx.gbl... > Norm, > > Thanks for that. Forgive this chap his stupid Sunday afternoon ramblings, > but I was declaring the ListBox as Object so I wouldn't in this instance > see the drop down list (for this I apologise as I should've mentioned it) > and from my observations in the past, I have never noticed the optional > [Index] parameter. > > Does it only allow 0 as the value for this Index? > answered just by pressing F1. -- Mike Microsoft MVP Visual Basic MikeD,
Point Taken! and thanks again. Alastair Show quoteHide quote "MikeD" <nob***@nowhere.edu> wrote in message news:O1bLpnHQGHA.4452@TK2MSFTNGP10.phx.gbl... > > "Alastair MacFarlane" <anonym***@microsoft.com> wrote in message > news:eLaKmrGQGHA.1096@TK2MSFTNGP11.phx.gbl... >> Norm, >> >> Thanks for that. Forgive this chap his stupid Sunday afternoon ramblings, >> but I was declaring the ListBox as Object so I wouldn't in this instance >> see the drop down list (for this I apologise as I should've mentioned it) >> and from my observations in the past, I have never noticed the optional >> [Index] parameter. >> >> Does it only allow 0 as the value for this Index? >> > > > You REALLY need to read VB's Help. Everything you've asked could have been > answered just by pressing F1. > > -- > Mike > Microsoft MVP Visual Basic > > > No, you can use other index values as long as they are in the valid range...
meaning if the list has only 3 items, you can't specify 5. For example, this works... Private Sub Form_Load() List1.AddItem "a" List1.AddItem "d" List1.AddItem "b" End Sub Private Sub Command1_Click() List1.AddItem "c (inserted)", 2 End Sub Show quoteHide quote "Alastair MacFarlane" <anonym***@microsoft.com> wrote in message news:OkQkyDGQGHA.4952@TK2MSFTNGP09.phx.gbl... > Thanks MikeD, > > I never realised there was another parameter after the item to be added. It > never appears in a drop down list for this method. Why not MikeD? Is 0 the > only value that can be added? If I try to say 1, I get an error. This will > do and I appreciate your help. > > I would like the first Item on the list always to stay the same, for example > "Loading progress...". This is not that important. > > I appreciate your speedy reply and help. > > Alastair MacFarlane > > "MikeD" <nob***@nowhere.edu> wrote in message > news:egN58wFQGHA.1040@TK2MSFTNGP12.phx.gbl... > > > > "Alastair MacFarlane" <anonym***@microsoft.com> wrote in message > > news:OoaP7cFQGHA.4952@TK2MSFTNGP09.phx.gbl... > >> Dear All, > >> > >> Is it possible to add an item to a list box so the last entered item > >> would be the first on the list or at a position of my choice, for > >> example: > >> > >> List1.AddItem "1" > >> List1.AddItem "2" > >> List1.AddItem "3" > >> > >> ... would give you 1, 2, 3 in your list. How can I make it 3, 2, 1 when > >> the AddItem method has be done in a specific order. Is the only way to > >> create an array and feed the array values into the List in reverse order? > > > > Did you bother to read VB's Help on the AddItem method? There's an > > optional Index argument you can specify to add an item at any given > > position (assuming it's a valid position). Note that the Sorted property > > must be False. This will do what you want: > > > > List1.AddItem "1", 0 > > List1.AddItem "2", 0 > > List1.AddItem "3", 0 > > > > Basically, you're just adding each item as the first item. > > > > -- > > Mike > > Microsoft MVP Visual Basic > > > > > > I'am looking for a way to store a list from one "session" to the next and
have it editable by the user. I use "additem" for a Listbox, say in a procedure, then close the form. The items were visible after the procedure, but disappeared upon closing the form. From the reading I have done, it appears the List property is or creates an array. How can I save this array? Show quoteHide quote "BeastFish" wrote: > No, you can use other index values as long as they are in the valid range... > meaning if the list has only 3 items, you can't specify 5. For example, > this works... > > Private Sub Form_Load() > List1.AddItem "a" > List1.AddItem "d" > List1.AddItem "b" > End Sub > > Private Sub Command1_Click() > List1.AddItem "c (inserted)", 2 > End Sub > > > > "Alastair MacFarlane" <anonym***@microsoft.com> wrote in message > news:OkQkyDGQGHA.4952@TK2MSFTNGP09.phx.gbl... > > Thanks MikeD, > > > > I never realised there was another parameter after the item to be added. > It > > never appears in a drop down list for this method. Why not MikeD? Is 0 the > > only value that can be added? If I try to say 1, I get an error. This will > > do and I appreciate your help. > > > > I would like the first Item on the list always to stay the same, for > example > > "Loading progress...". This is not that important. > > > > I appreciate your speedy reply and help. > > > > Alastair MacFarlane > > > > "MikeD" <nob***@nowhere.edu> wrote in message > > news:egN58wFQGHA.1040@TK2MSFTNGP12.phx.gbl... > > > > > > "Alastair MacFarlane" <anonym***@microsoft.com> wrote in message > > > news:OoaP7cFQGHA.4952@TK2MSFTNGP09.phx.gbl... > > >> Dear All, > > >> > > >> Is it possible to add an item to a list box so the last entered item > > >> would be the first on the list or at a position of my choice, for > > >> example: > > >> > > >> List1.AddItem "1" > > >> List1.AddItem "2" > > >> List1.AddItem "3" > > >> > > >> ... would give you 1, 2, 3 in your list. How can I make it 3, 2, 1 when > > >> the AddItem method has be done in a specific order. Is the only way to > > >> create an array and feed the array values into the List in reverse > order? > > > > > > Did you bother to read VB's Help on the AddItem method? There's an > > > optional Index argument you can specify to add an item at any given > > > position (assuming it's a valid position). Note that the Sorted property > > > must be False. This will do what you want: > > > > > > List1.AddItem "1", 0 > > > List1.AddItem "2", 0 > > > List1.AddItem "3", 0 > > > > > > Basically, you're just adding each item as the first item. > > > > > > -- > > > Mike > > > Microsoft MVP Visual Basic > > > > > > > > > > > > > You have to do that yourself, there's nothing automatic. Cycle through the
listbox items and save them to a file. Then read from the file and load them into the listbox. Show quoteHide quote "cush" <c***@discussions.microsoft.com> wrote in message news:A9BFE5AF-7283-4AF2-879C-E9688F4AB31E@microsoft.com... > I'am looking for a way to store a list from one "session" to the next and > have it editable by the user. > I use "additem" for a Listbox, say in a procedure, then close the form. The > items were visible after the procedure, but disappeared upon closing the > form. From the reading I have done, it appears the List property is or > creates an array. How can I save this array? > > "BeastFish" wrote: > > > No, you can use other index values as long as they are in the valid range... > > meaning if the list has only 3 items, you can't specify 5. For example, > > this works... > > > > Private Sub Form_Load() > > List1.AddItem "a" > > List1.AddItem "d" > > List1.AddItem "b" > > End Sub > > > > Private Sub Command1_Click() > > List1.AddItem "c (inserted)", 2 > > End Sub > > > > > > > > "Alastair MacFarlane" <anonym***@microsoft.com> wrote in message > > news:OkQkyDGQGHA.4952@TK2MSFTNGP09.phx.gbl... > > > Thanks MikeD, > > > > > > I never realised there was another parameter after the item to be added. > > It > > > never appears in a drop down list for this method. Why not MikeD? Is 0 the > > > only value that can be added? If I try to say 1, I get an error. This will > > > do and I appreciate your help. > > > > > > I would like the first Item on the list always to stay the same, for > > example > > > "Loading progress...". This is not that important. > > > > > > I appreciate your speedy reply and help. > > > > > > Alastair MacFarlane > > > > > > "MikeD" <nob***@nowhere.edu> wrote in message > > > news:egN58wFQGHA.1040@TK2MSFTNGP12.phx.gbl... > > > > > > > > "Alastair MacFarlane" <anonym***@microsoft.com> wrote in message > > > > news:OoaP7cFQGHA.4952@TK2MSFTNGP09.phx.gbl... > > > >> Dear All, > > > >> > > > >> Is it possible to add an item to a list box so the last entered item > > > >> would be the first on the list or at a position of my choice, for > > > >> example: > > > >> > > > >> List1.AddItem "1" > > > >> List1.AddItem "2" > > > >> List1.AddItem "3" > > > >> > > > >> ... would give you 1, 2, 3 in your list. How can I make it 3, 2, 1 when > > > >> the AddItem method has be done in a specific order. Is the only way to > > > >> create an array and feed the array values into the List in reverse > > order? > > > > > > > > Did you bother to read VB's Help on the AddItem method? There's an > > > > optional Index argument you can specify to add an item at any given > > > > position (assuming it's a valid position). Note that the Sorted property > > > > must be False. This will do what you want: > > > > > > > > List1.AddItem "1", 0 > > > > List1.AddItem "2", 0 > > > > List1.AddItem "3", 0 > > > > > > > > Basically, you're just adding each item as the first item. > > > > > > > > -- > > > > Mike > > > > Microsoft MVP Visual Basic > > > > > > > > > > > > > > > > > > > > |
|||||||||||||||||||||||