home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / vb_code1 / multisel / multsel.txt < prev    next >
Text File  |  1992-01-03  |  4KB  |  84 lines

  1.  
  2.                   Multiple Selection Listbox for Visual Basic
  3.                       Version 0.2  1/4/91 by Mark Gamber
  4.  
  5. *-----------------------------------------------------------------------------*
  6.  
  7.    One control I have needed in Visual Basic is a multiple selection listbox.
  8. I am assuming I am not alone by sending this into the wild blue yonder. To use
  9. the control in your programs, select "Add File..." from the "File" menu of
  10. Visual Basic and select "MULTSEL.VBX". If the control bitmap is added to the
  11. toolbox, you're ready to begin using the listbox.
  12.  
  13. *-----------------------------------------------------------------------------*
  14.  
  15.    Improvements have been made on the original, Version 0.1, which make this
  16. version far easier to use and understand. First, a quick rundown of the various
  17. things the control offers and then, onto an example program in Visual Basic.
  18.  
  19. *-----------------------------------------------------------------------------*
  20.  
  21.    The control is addressed as MultipleSel. Thus, the first listbox on a form
  22. is addresses as MultipleSel1 and so on. Adding to and removing from the list-
  23. -box is the same as with the standard Visual Basic listbox. For example, to add
  24. an item the listbox, you could use this line:
  25.  
  26.    MultipleSel1.AddItem "We add this line"
  27.  
  28. To remove line 0 (the one on the top), you might use this line:
  29.  
  30.    MultipleSel1.RemoveItem 0
  31.  
  32. Easy, huh? Nothing new there. Along with those familiar functions comes
  33. ListCount which returns the number of items in the listbox. For example:
  34.  
  35.    num = MultipleSel1.ListCount
  36.  
  37. ListIndex is the first fork in the road from the standard listbox. Since there
  38. may be several items selected, you cannot select any particular item. Instead,
  39. this returns whether or not an item has been selected. For example, if we want
  40. to see if item four has been selected, we could use this line:
  41.  
  42.    if MultipleSel1.ListIndex(3) then ...
  43.  
  44. Remember, it starts at zero so item four is indexed as three. Anyway, if the
  45. item was selected, the return value is TRUE (-1). If unselected, the return
  46. value is FALSE (0). To see if items one through ten have been selected, we could
  47. use this loop:
  48.  
  49.    for i% = 0 to 9
  50.       if MultipleSel1.ListIndex(i%) then ...
  51.    next
  52.  
  53. Finally, to retrieve the text of a particular item, we use the List function.
  54. For example, to get the text for item zero (the top of the listbox):
  55.  
  56.    t$ = MultipleSel1.List(0)
  57.  
  58. In a loop, we could use something like this:
  59.  
  60.    for i% = 0 to 10
  61.       if MultipleSel1.ListIndex(i%) then
  62.          Picture1.Print MultipleSel1.List(i%)
  63.       endif
  64.    next
  65.  
  66. The above loop will print all selected items in the listbox. Nice, huh?
  67.  
  68. *-----------------------------------------------------------------------------*
  69.  
  70.    So there's a basic outline of the listbox. The example program is called
  71. MSELTEST.EXE and is available with this file. I suggest you look at the code
  72. for Command1 and Command2 buttons which is what controls the adding and testing
  73. of the listbox items.
  74.  
  75. *-----------------------------------------------------------------------------*
  76.  
  77.    As always, this program is free as long as you agree that I did nothing to
  78. ruin your life in any way. After all, it's just a simple control. I may be
  79. reached for questions, comments, suggestions and praise via America Online,
  80. mail address MarkG85. I do NOT answer phone calls as that's reserved for my
  81. real job. I hope you find this control as useful as I did.
  82.  
  83.  
  84.