home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / code / design / lbtabs / listdemo.txt < prev   
Text File  |  1995-02-26  |  5KB  |  170 lines

  1. Option Explicit
  2.  
  3. 'Updated 01/06/95 - DULIST.BAS Fixes and Enhancements
  4. '
  5. '                   dulist_tfSetListCols
  6. '                   --------------------
  7. '                   Fixed bug that caused an endless
  8. '                   loop if the last character of a
  9. '                   listbox item string was a Chr$(9) tab.
  10. '
  11. '                   dulist_sGetColumn
  12. '                   -----------------
  13. '                   New routine to extract data, by column,
  14. '                   from a tab-delimited string.
  15. '
  16. '                   dulist_AddHorizScrollBar
  17. '                   ------------------------
  18. '                   New routine to add a horizontal
  19. '                   scrollbar to a listbox.
  20.  
  21.  
  22. 'If you have questions, comments, or suggestions for
  23. 'improving the code presented here, please forward them
  24. 'to me; your input is welcome:
  25. '
  26. '        Brad Kaenel
  27. '        PC HELP-LINE
  28. '        35250 Silver Leaf Circle
  29. '        Yucaipa, CA  92399
  30. '        United States
  31. '        CIS: 72357,3523
  32. '        Internet: 72357.3523@compuserve.com
  33. '
  34.  
  35. 'Although multi-column listboxes are a common
  36. 'requirement, they are difficult to accomplish
  37. 'in VB.
  38.  
  39. 'A simple solution is to select a mono-spaced
  40. 'font for the listbox and align the data manually,
  41. 'but this is not always visually appealing.  However,
  42. 'with a little more work you can set dynamic tabstops
  43. 'that will work with proportional fonts.
  44.  
  45. 'This sample demonstrates how to set tabstops in a listbox,
  46. 'using a borderless, disabled text box for the column
  47. 'headings.  It also shows how to "pre-select" a listbox
  48. 'or combobox item, using Windows API functions.
  49.  
  50. Dim sFruit(10) As String, sMyFruit As String
  51. Dim nTabStopsSet As Integer
  52.  
  53. Sub cboSelect_Click ()
  54.  
  55. sMyFruit = cboSelect.Text
  56.  
  57. txtSearch.Text = sMyFruit  'synchronize the textbox
  58. Call SelectFruit           'synchronize the listbox
  59.  
  60. End Sub
  61.  
  62. Sub cmdExit_Click ()
  63.  
  64. Unload frmListDemo
  65.  
  66. End Sub
  67.  
  68. Sub cmdSetColumns_Click ()
  69.  
  70. Call SetTabStops
  71.  
  72. End Sub
  73.  
  74. Sub Form_Load ()
  75.  
  76. Dim nFruitCount As Integer
  77. Dim sTAB As String
  78. sTAB = Chr$(9)
  79.  
  80.  
  81. 'add a horiz scrollbar
  82.  
  83. Call dulist_AddHorizScrollBar(lstFruits, 0)
  84.  
  85.  
  86. 'load up some multi-column data
  87.  
  88. txtListHeadings.Text = "Fruit" + sTAB + "Opinion" + sTAB + "Color"
  89.  
  90. sFruit(1) = "Oranges" + sTAB + "Good" + sTAB + "Orange, of course"
  91. sFruit(2) = "Bananas" + sTAB + "Munchy" + sTAB + "Yellow"
  92. sFruit(3) = "Apples" + sTAB + "Delicious" + sTAB + "Red"
  93. sFruit(4) = "Blueberries" + sTAB + "Nah" + sTAB + "Blue"
  94. sFruit(5) = "Plums" + sTAB + "Better than prunes" + sTAB + "Purple"
  95. sFruit(6) = "Watermelons" + sTAB + "Marvelous" + sTAB + "Red and Green"
  96. sFruit(7) = "Cherries" + sTAB + "Ummm..." + sTAB + "Bright Red"
  97. sFruit(8) = "Mangos" + sTAB + "Juicy" + sTAB + "No idea"
  98. sFruit(9) = "Kiwis" + sTAB + "Kinda weird" + sTAB + "Fuzzy Green"
  99. sFruit(10) = "Peaches" + sTAB + "OK" + sTAB + "Peach, I guess(?)"
  100.  
  101. For nFruitCount = 1 To UBound(sFruit)
  102.    lstFruits.AddItem sFruit(nFruitCount)
  103.    
  104.    'comboboxes don't support tabstops, so use only the first column string
  105.  
  106.    cboSelect.AddItem dulist_sGetColumn(sFruit(nFruitCount), 1)
  107. Next
  108.  
  109. For nFruitCount = 0 To Screen.FontCount - 1
  110.    lstFonts.AddItem Screen.Fonts(nFruitCount)
  111. Next
  112.  
  113. nTabStopsSet = True
  114. cmdSetColumns.Value = True  'trigger tab stops
  115.  
  116. End Sub
  117.  
  118. Sub lstFonts_Click ()
  119.  
  120. lstFruits.FontName = lstFonts.List(lstFonts.ListIndex)
  121. lstFruits.Height = (lstFonts.Top - lstFruits.Top) - 20
  122.  
  123. nTabStopsSet = Not nTabStopsSet
  124. cmdSetColumns.Value = True  'trigger tab stops
  125.  
  126. End Sub
  127.  
  128. Sub lstFruits_Click ()
  129.  
  130. sMyFruit = dulist_sGetColumn((lstFruits.List(lstFruits.ListIndex)), 1)
  131.  
  132. txtSearch.Text = sMyFruit  'synchronize the textbox
  133. Call SelectFruit           'synchronize the combobox
  134.  
  135. End Sub
  136.  
  137. Sub SelectFruit ()
  138.  
  139. If dulist_tfSelectListItem(lstFruits, sMyFruit) Then
  140.    If dulist_tfSelectListItem(cboSelect, sMyFruit) Then
  141.    End If
  142. End If
  143.  
  144. End Sub
  145.  
  146. Sub SetTabStops ()
  147.  
  148. If nTabStopsSet Then
  149.    If dulist_tfSetListCols(lstFruits, txtListHeadings, False, True) Then
  150.       cmdSetColumns.Caption = "Set &Custom Tab Stops"
  151.       nTabStopsSet = Not nTabStopsSet
  152.    End If
  153. Else
  154.    If dulist_tfSetListCols(lstFruits, txtListHeadings, False, False) Then
  155.       cmdSetColumns.Caption = "Reset &Default Tab Stops"
  156.       nTabStopsSet = Not nTabStopsSet
  157.    End If
  158. End If
  159.  
  160. End Sub
  161.  
  162. Sub txtSearch_Change ()
  163.  
  164. sMyFruit = txtSearch.Text
  165.  
  166. Call SelectFruit           'synchronize the listbox
  167.                            'and the combobox
  168. End Sub
  169.  
  170.