home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / vb_code1 / listdemo / listdemo.frm < prev    next >
Text File  |  1993-10-22  |  6KB  |  214 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    Caption         =   "List Controls: Columns and Selections"
  4.    ClientHeight    =   4335
  5.    ClientLeft      =   2280
  6.    ClientTop       =   1650
  7.    ClientWidth     =   5760
  8.    Height          =   4740
  9.    Left            =   2220
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   4335
  12.    ScaleWidth      =   5760
  13.    Top             =   1305
  14.    Width           =   5880
  15.    Begin TextBox Text2 
  16.       Height          =   285
  17.       Left            =   240
  18.       TabIndex        =   3
  19.       Top             =   2400
  20.       Width           =   5295
  21.    End
  22.    Begin CommandButton Command2 
  23.       Caption         =   "E&xit"
  24.       Height          =   495
  25.       Left            =   3000
  26.       TabIndex        =   6
  27.       Top             =   3600
  28.       Width           =   2535
  29.    End
  30.    Begin ListBox List2 
  31.       Height          =   1200
  32.       Left            =   240
  33.       Sorted          =   -1  'True
  34.       TabIndex        =   4
  35.       Top             =   2880
  36.       Width           =   2535
  37.    End
  38.    Begin TextBox Text1 
  39.       BorderStyle     =   0  'None
  40.       Enabled         =   0   'False
  41.       ForeColor       =   &H00C00000&
  42.       Height          =   255
  43.       Left            =   240
  44.       MultiLine       =   -1  'True
  45.       TabIndex        =   0
  46.       Text            =   "Text1"
  47.       Top             =   120
  48.       Width           =   855
  49.    End
  50.    Begin CommandButton Command1 
  51.       Caption         =   "Command1"
  52.       Height          =   495
  53.       Left            =   3000
  54.       TabIndex        =   5
  55.       Top             =   3000
  56.       Width           =   2535
  57.    End
  58.    Begin ListBox List1 
  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        =   1
  69.       Top             =   480
  70.       Width           =   5295
  71.    End
  72.    Begin ComboBox Combo1 
  73.       Height          =   300
  74.       Left            =   240
  75.       Sorted          =   -1  'True
  76.       Style           =   2  'Dropdown List
  77.       TabIndex        =   2
  78.       Top             =   1920
  79.       Width           =   5295
  80.    End
  81. End
  82. 'Although multi-column listboxes are a common
  83. 'requirement, they are difficult to accomplish
  84. 'in VB.
  85.  
  86. 'A simple solution is to select a mono-spaced
  87. 'font for the listbox and align the data manually,
  88. 'but this is not always visually appealing.  However,
  89. 'with a little more work you can set dynamic tabstops
  90. 'that will work with proportional fonts.
  91.  
  92. 'This sample shows how to set tabstops in a listbox,
  93. 'using a borderless, disabled text box for the column
  94. 'headings.  It also shows how to "pre-select" a listbox
  95. 'or combobox item, using Windows API functions.
  96.  
  97. Option Explicit
  98.  
  99. Dim Fruit(10) As String, MyFruit As String
  100. Dim TabStopsSet As Integer
  101.  
  102. Sub Combo1_Click ()
  103.  
  104. MyFruit = Combo1.Text
  105. Text2.Text = MyFruit
  106.  
  107. Call SelectFruit  'synchronize the listbox
  108.  
  109. End Sub
  110.  
  111. Sub Command1_Click ()
  112.  
  113. Call SetTabStops
  114.  
  115. End Sub
  116.  
  117. Sub Command2_Click ()
  118.  
  119. Unload Form1
  120.  
  121. End Sub
  122.  
  123. Sub Form_Load ()
  124.  
  125. Dim F As Integer
  126.  
  127. 'load up some multi-column data
  128.  
  129. Text1.Text = "Fruit" + Chr$(9) + "Opinion" + Chr$(9) + "Color"
  130.  
  131. Fruit(1) = "Oranges" + Chr$(9) + "Good" + Chr$(9) + "Orange, of course"
  132. Fruit(2) = "Bananas" + Chr$(9) + "Munchy" + Chr$(9) + "Yellow"
  133. Fruit(3) = "Apples" + Chr$(9) + "Delicious" + Chr$(9) + "Red"
  134. Fruit(4) = "Blueberries" + Chr$(9) + "Nah" + Chr$(9) + "Blue"
  135. Fruit(5) = "Plums" + Chr$(9) + "Better than prunes" + Chr$(9) + "Purple"
  136. Fruit(6) = "Watermelons" + Chr$(9) + "Marvelous" + Chr$(9) + "Red and Green"
  137. Fruit(7) = "Cherries" + Chr$(9) + "Ummm..." + Chr$(9) + "Bright Red"
  138. Fruit(8) = "Mangos" + Chr$(9) + "Juicy" + Chr$(9) + "No idea"
  139. Fruit(9) = "Kiwis" + Chr$(9) + "Kinda weird" + Chr$(9) + "Fuzzy Green"
  140. Fruit(10) = "Peaches" + Chr$(9) + "OK" + Chr$(9) + "Peach, I guess(?)"
  141.  
  142. For F = 1 To UBound(Fruit)
  143.    List1.AddItem Fruit(F)
  144.    
  145.    'comboboxes don't support columns, so only use first string
  146.  
  147.    Combo1.AddItem Left$(Fruit(F), InStr(Fruit(F), Chr$(9)) - 1)
  148. Next
  149.  
  150. For F = 0 To Screen.FontCount - 1
  151.    List2.AddItem Screen.Fonts(F)
  152. Next
  153.  
  154. TabStopsSet = True
  155. Command1.Value = True  'trigger tab stops
  156.  
  157. End Sub
  158.  
  159. Sub List1_Click ()
  160.  
  161. MyFruit = List1.Text
  162.  
  163. If Len(MyFruit) > 0 Then
  164.    MyFruit = Left$(MyFruit, InStr(MyFruit, Chr$(9)) - 1)
  165.    Text2.Text = MyFruit
  166.  
  167.    Call SelectFruit  'synchronize the combobox
  168. End If
  169.  
  170. End Sub
  171.  
  172. Sub List2_Click ()
  173.  
  174. List1.FontName = List2.List(List2.ListIndex)
  175. List1.Height = (Combo1.Top - List1.Top) - 10
  176.  
  177. TabStopsSet = Not TabStopsSet
  178. Command1.Value = True  'trigger tab stops
  179.  
  180. End Sub
  181.  
  182. Sub SelectFruit ()
  183.  
  184. If SelectListItem(List1, MyFruit) Then
  185.    If SelectListItem(Combo1, MyFruit) Then
  186.    End If
  187. End If
  188.  
  189. End Sub
  190.  
  191. Sub SetTabStops ()
  192.  
  193. If TabStopsSet Then
  194.    If SetListCols(List1, Text1, False, True) Then
  195.       Command1.Caption = "Set &Custom Tab Stops"
  196.       TabStopsSet = Not TabStopsSet
  197.    End If
  198. Else
  199.    If SetListCols(List1, Text1, False, False) Then
  200.       Command1.Caption = "Reset &Default Tab Stops"
  201.       TabStopsSet = Not TabStopsSet
  202.    End If
  203. End If
  204.  
  205. End Sub
  206.  
  207. Sub Text2_Change ()
  208.  
  209. MyFruit = Text2.Text
  210. Call SelectFruit  'synchronize the listbox and combobox
  211.  
  212. End Sub
  213.  
  214.