home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / code / design / lbtabs / listdemo.frm < prev    next >
Text File  |  1995-02-18  |  7KB  |  267 lines

  1. VERSION 2.00
  2. Begin Form frmListDemo 
  3.    Caption         =   "List Control Demo"
  4.    ClientHeight    =   4800
  5.    ClientLeft      =   2280
  6.    ClientTop       =   1650
  7.    ClientWidth     =   5760
  8.    Height          =   5205
  9.    Left            =   2220
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   4800
  12.    ScaleWidth      =   5760
  13.    Top             =   1305
  14.    Width           =   5880
  15.    Begin TextBox txtSearch 
  16.       Height          =   285
  17.       Left            =   240
  18.       TabIndex        =   1
  19.       Top             =   360
  20.       Width           =   5295
  21.    End
  22.    Begin CommandButton cmdExit 
  23.       Caption         =   "E&xit"
  24.       Height          =   495
  25.       Left            =   3000
  26.       TabIndex        =   8
  27.       Top             =   4080
  28.       Width           =   2535
  29.    End
  30.    Begin ListBox lstFonts 
  31.       Height          =   1200
  32.       Left            =   240
  33.       Sorted          =   -1  'True
  34.       TabIndex        =   6
  35.       Top             =   3360
  36.       Width           =   2535
  37.    End
  38.    Begin TextBox txtListHeadings 
  39.       BorderStyle     =   0  'None
  40.       Enabled         =   0   'False
  41.       ForeColor       =   &H00C00000&
  42.       Height          =   255
  43.       Left            =   240
  44.       MultiLine       =   -1  'True
  45.       TabIndex        =   4
  46.       Text            =   "(headings)"
  47.       Top             =   1440
  48.       Width           =   855
  49.    End
  50.    Begin CommandButton cmdSetColumns 
  51.       Caption         =   "(set columns)"
  52.       Height          =   495
  53.       Left            =   3000
  54.       TabIndex        =   7
  55.       Top             =   3480
  56.       Width           =   2535
  57.    End
  58.    Begin ListBox lstFruits 
  59.       FontBold        =   -1  'True
  60.       FontItalic      =   0   'False
  61.       FontName        =   "MS Sans Serif"
  62.       FontSize        =   9.75
  63.       FontStrikethru  =   0   'False
  64.       FontUnderline   =   0   'False
  65.       Height          =   1230
  66.       Left            =   240
  67.       Sorted          =   -1  'True
  68.       TabIndex        =   5
  69.       Top             =   1800
  70.       Width           =   5295
  71.    End
  72.    Begin ComboBox cboSelect 
  73.       Height          =   300
  74.       Left            =   240
  75.       Sorted          =   -1  'True
  76.       Style           =   2  'Dropdown List
  77.       TabIndex        =   3
  78.       Top             =   1080
  79.       Width           =   5295
  80.    End
  81.    Begin Label lblSearch 
  82.       Caption         =   "Search:"
  83.       Height          =   255
  84.       Left            =   240
  85.       TabIndex        =   0
  86.       Top             =   120
  87.       Width           =   1455
  88.    End
  89.    Begin Label lblSelect 
  90.       Caption         =   "Select:"
  91.       Height          =   255
  92.       Left            =   240
  93.       TabIndex        =   2
  94.       Top             =   840
  95.       Width           =   1455
  96.    End
  97. End
  98. Option Explicit
  99.  
  100. 'Updated 01/06/95 - DULIST.BAS Fixes and Enhancements
  101. '
  102. '                   dulist_tfSetListCols
  103. '                   --------------------
  104. '                   Fixed bug that caused an endless
  105. '                   loop if the last character of a
  106. '                   listbox item string was a Chr$(9) tab.
  107. '
  108. '                   dulist_sGetColumn
  109. '                   -----------------
  110. '                   New routine to extract data, by column,
  111. '                   from a tab-delimited string.
  112. '
  113. '                   dulist_AddHorizScrollBar
  114. '                   ------------------------
  115. '                   New routine to add a horizontal
  116. '                   scrollbar to a listbox.
  117.  
  118.  
  119. 'If you have questions, comments, or suggestions for
  120. 'improving the code presented here, please forward them
  121. 'to me; your input is welcome:
  122. '
  123. '        Brad Kaenel
  124. '        PC HELP-LINE
  125. '        35250 Silver Leaf Circle
  126. '        Yucaipa, CA  92399
  127. '        United States
  128. '        CIS: 72357,3523
  129. '        Internet: 72357.3523@compuserve.com
  130. '
  131.  
  132. 'Although multi-column listboxes are a common
  133. 'requirement, they are difficult to accomplish
  134. 'in VB.
  135.  
  136. 'A simple solution is to select a mono-spaced
  137. 'font for the listbox and align the data manually,
  138. 'but this is not always visually appealing.  However,
  139. 'with a little more work you can set dynamic tabstops
  140. 'that will work with proportional fonts.
  141.  
  142. 'This sample demonstrates how to set tabstops in a listbox,
  143. 'using a borderless, disabled text box for the column
  144. 'headings.  It also shows how to "pre-select" a listbox
  145. 'or combobox item, using Windows API functions.
  146.  
  147. Dim sFruit(10) As String, sMyFruit As String
  148. Dim nTabStopsSet As Integer
  149.  
  150. Sub cboSelect_Click ()
  151.  
  152. sMyFruit = cboSelect.Text
  153.  
  154. txtSearch.Text = sMyFruit  'synchronize the textbox
  155. Call SelectFruit           'synchronize the listbox
  156.  
  157. End Sub
  158.  
  159. Sub cmdExit_Click ()
  160.  
  161. Unload frmListDemo
  162.  
  163. End Sub
  164.  
  165. Sub cmdSetColumns_Click ()
  166.  
  167. Call SetTabStops
  168.  
  169. End Sub
  170.  
  171. Sub Form_Load ()
  172.  
  173. Dim nFruitCount As Integer
  174. Dim sTAB As String
  175. sTAB = Chr$(9)
  176.  
  177.  
  178. 'add a horiz scrollbar
  179.  
  180. Call dulist_AddHorizScrollBar(lstFruits, 0)
  181.  
  182.  
  183. 'load up some multi-column data
  184.  
  185. txtListHeadings.Text = "Fruit" + sTAB + "Opinion" + sTAB + "Color"
  186.  
  187. sFruit(1) = "Oranges" + sTAB + "Good" + sTAB + "Orange, of course"
  188. sFruit(2) = "Bananas" + sTAB + "Munchy" + sTAB + "Yellow"
  189. sFruit(3) = "Apples" + sTAB + "Delicious" + sTAB + "Red"
  190. sFruit(4) = "Blueberries" + sTAB + "Nah" + sTAB + "Blue"
  191. sFruit(5) = "Plums" + sTAB + "Better than prunes" + sTAB + "Purple"
  192. sFruit(6) = "Watermelons" + sTAB + "Marvelous" + sTAB + "Red and Green"
  193. sFruit(7) = "Cherries" + sTAB + "Ummm..." + sTAB + "Bright Red"
  194. sFruit(8) = "Mangos" + sTAB + "Juicy" + sTAB + "No idea"
  195. sFruit(9) = "Kiwis" + sTAB + "Kinda weird" + sTAB + "Fuzzy Green"
  196. sFruit(10) = "Peaches" + sTAB + "OK" + sTAB + "Peach, I guess(?)"
  197.  
  198. For nFruitCount = 1 To UBound(sFruit)
  199.    lstFruits.AddItem sFruit(nFruitCount)
  200.    
  201.    'comboboxes don't support tabstops, so use only the first column string
  202.  
  203.    cboSelect.AddItem dulist_sGetColumn(sFruit(nFruitCount), 1)
  204. Next
  205.  
  206. For nFruitCount = 0 To Screen.FontCount - 1
  207.    lstFonts.AddItem Screen.Fonts(nFruitCount)
  208. Next
  209.  
  210. nTabStopsSet = True
  211. cmdSetColumns.Value = True  'trigger tab stops
  212.  
  213. End Sub
  214.  
  215. Sub lstFonts_Click ()
  216.  
  217. lstFruits.FontName = lstFonts.List(lstFonts.ListIndex)
  218. lstFruits.Height = (lstFonts.Top - lstFruits.Top) - 20
  219.  
  220. nTabStopsSet = Not nTabStopsSet
  221. cmdSetColumns.Value = True  'trigger tab stops
  222.  
  223. End Sub
  224.  
  225. Sub lstFruits_Click ()
  226.  
  227. sMyFruit = dulist_sGetColumn((lstFruits.List(lstFruits.ListIndex)), 1)
  228.  
  229. txtSearch.Text = sMyFruit  'synchronize the textbox
  230. Call SelectFruit           'synchronize the combobox
  231.  
  232. End Sub
  233.  
  234. Sub SelectFruit ()
  235.  
  236. If dulist_tfSelectListItem(lstFruits, sMyFruit) Then
  237.    If dulist_tfSelectListItem(cboSelect, sMyFruit) Then
  238.    End If
  239. End If
  240.  
  241. End Sub
  242.  
  243. Sub SetTabStops ()
  244.  
  245. If nTabStopsSet Then
  246.    If dulist_tfSetListCols(lstFruits, txtListHeadings, False, True) Then
  247.       cmdSetColumns.Caption = "Set &Custom Tab Stops"
  248.       nTabStopsSet = Not nTabStopsSet
  249.    End If
  250. Else
  251.    If dulist_tfSetListCols(lstFruits, txtListHeadings, False, False) Then
  252.       cmdSetColumns.Caption = "Reset &Default Tab Stops"
  253.       nTabStopsSet = Not nTabStopsSet
  254.    End If
  255. End If
  256.  
  257. End Sub
  258.  
  259. Sub txtSearch_Change ()
  260.  
  261. sMyFruit = txtSearch.Text
  262.  
  263. Call SelectFruit           'synchronize the listbox
  264.                            'and the combobox
  265. End Sub
  266.  
  267.