home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / code / design / lbtabs / listdemo.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-02-18  |  7.3 KB  |  208 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. Option Explicit
  98. 'Updated 01/06/95 - DULIST.BAS Fixes and Enhancements
  99. '                   dulist_tfSetListCols
  100. '                   --------------------
  101. '                   Fixed bug that caused an endless
  102. '                   loop if the last character of a
  103. '                   listbox item string was a Chr$(9) tab.
  104. '                   dulist_sGetColumn
  105. '                   -----------------
  106. '                   New routine to extract data, by column,
  107. '                   from a tab-delimited string.
  108. '                   dulist_AddHorizScrollBar
  109. '                   ------------------------
  110. '                   New routine to add a horizontal
  111. '                   scrollbar to a listbox.
  112. 'If you have questions, comments, or suggestions for
  113. 'improving the code presented here, please forward them
  114. 'to me; your input is welcome:
  115. '        Brad Kaenel
  116. '        PC HELP-LINE
  117. '        35250 Silver Leaf Circle
  118. '        Yucaipa, CA  92399
  119. '        United States
  120. '        CIS: 72357,3523
  121. '        Internet: 72357.3523@compuserve.com
  122. 'Although multi-column listboxes are a common
  123. 'requirement, they are difficult to accomplish
  124. 'in VB.
  125. 'A simple solution is to select a mono-spaced
  126. 'font for the listbox and align the data manually,
  127. 'but this is not always visually appealing.  However,
  128. 'with a little more work you can set dynamic tabstops
  129. 'that will work with proportional fonts.
  130. 'This sample demonstrates how to set tabstops in a listbox,
  131. 'using a borderless, disabled text box for the column
  132. 'headings.  It also shows how to "pre-select" a listbox
  133. 'or combobox item, using Windows API functions.
  134. Dim sFruit(10) As String, sMyFruit As String
  135. Dim nTabStopsSet As Integer
  136. Sub cboSelect_Click ()
  137. sMyFruit = cboSelect.Text
  138. txtSearch.Text = sMyFruit  'synchronize the textbox
  139. Call SelectFruit           'synchronize the listbox
  140. End Sub
  141. Sub cmdExit_Click ()
  142. Unload frmListDemo
  143. End Sub
  144. Sub cmdSetColumns_Click ()
  145. Call SetTabStops
  146. End Sub
  147. Sub Form_Load ()
  148. Dim nFruitCount As Integer
  149. Dim sTAB As String
  150. sTAB = Chr$(9)
  151. 'add a horiz scrollbar
  152. Call dulist_AddHorizScrollBar(lstFruits, 0)
  153. 'load up some multi-column data
  154. txtListHeadings.Text = "Fruit" + sTAB + "Opinion" + sTAB + "Color"
  155. sFruit(1) = "Oranges" + sTAB + "Good" + sTAB + "Orange, of course"
  156. sFruit(2) = "Bananas" + sTAB + "Munchy" + sTAB + "Yellow"
  157. sFruit(3) = "Apples" + sTAB + "Delicious" + sTAB + "Red"
  158. sFruit(4) = "Blueberries" + sTAB + "Nah" + sTAB + "Blue"
  159. sFruit(5) = "Plums" + sTAB + "Better than prunes" + sTAB + "Purple"
  160. sFruit(6) = "Watermelons" + sTAB + "Marvelous" + sTAB + "Red and Green"
  161. sFruit(7) = "Cherries" + sTAB + "Ummm..." + sTAB + "Bright Red"
  162. sFruit(8) = "Mangos" + sTAB + "Juicy" + sTAB + "No idea"
  163. sFruit(9) = "Kiwis" + sTAB + "Kinda weird" + sTAB + "Fuzzy Green"
  164. sFruit(10) = "Peaches" + sTAB + "OK" + sTAB + "Peach, I guess(?)"
  165. For nFruitCount = 1 To UBound(sFruit)
  166.    lstFruits.AddItem sFruit(nFruitCount)
  167.    'comboboxes don't support tabstops, so use only the first column string
  168.    cboSelect.AddItem dulist_sGetColumn(sFruit(nFruitCount), 1)
  169. For nFruitCount = 0 To Screen.FontCount - 1
  170.    lstFonts.AddItem Screen.Fonts(nFruitCount)
  171. nTabStopsSet = True
  172. cmdSetColumns.Value = True  'trigger tab stops
  173. End Sub
  174. Sub lstFonts_Click ()
  175. lstFruits.FontName = lstFonts.List(lstFonts.ListIndex)
  176. lstFruits.Height = (lstFonts.Top - lstFruits.Top) - 20
  177. nTabStopsSet = Not nTabStopsSet
  178. cmdSetColumns.Value = True  'trigger tab stops
  179. End Sub
  180. Sub lstFruits_Click ()
  181. sMyFruit = dulist_sGetColumn((lstFruits.List(lstFruits.ListIndex)), 1)
  182. txtSearch.Text = sMyFruit  'synchronize the textbox
  183. Call SelectFruit           'synchronize the combobox
  184. End Sub
  185. Sub SelectFruit ()
  186. If dulist_tfSelectListItem(lstFruits, sMyFruit) Then
  187.    If dulist_tfSelectListItem(cboSelect, sMyFruit) Then
  188.    End If
  189. End If
  190. End Sub
  191. Sub SetTabStops ()
  192. If nTabStopsSet Then
  193.    If dulist_tfSetListCols(lstFruits, txtListHeadings, False, True) Then
  194.       cmdSetColumns.Caption = "Set &Custom Tab Stops"
  195.       nTabStopsSet = Not nTabStopsSet
  196.    End If
  197.    If dulist_tfSetListCols(lstFruits, txtListHeadings, False, False) Then
  198.       cmdSetColumns.Caption = "Reset &Default Tab Stops"
  199.       nTabStopsSet = Not nTabStopsSet
  200.    End If
  201. End If
  202. End Sub
  203. Sub txtSearch_Change ()
  204. sMyFruit = txtSearch.Text
  205. Call SelectFruit           'synchronize the listbox
  206.                            'and the combobox
  207. End Sub
  208.