home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / VISUAL_B / CODIGO_1 / LISTDEMO / LISTDEMO.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1993-10-22  |  5.4 KB  |  166 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. 'Although multi-column listboxes are a common
  82. 'requirement, they are difficult to accomplish
  83. 'in VB.
  84. 'A simple solution is to select a mono-spaced
  85. 'font for the listbox and align the data manually,
  86. 'but this is not always visually appealing.  However,
  87. 'with a little more work you can set dynamic tabstops
  88. 'that will work with proportional fonts.
  89. 'This sample shows how to set tabstops in a listbox,
  90. 'using a borderless, disabled text box for the column
  91. 'headings.  It also shows how to "pre-select" a listbox
  92. 'or combobox item, using Windows API functions.
  93. Option Explicit
  94. Dim Fruit(10) As String, MyFruit As String
  95. Dim TabStopsSet As Integer
  96. Sub Combo1_Click ()
  97. MyFruit = Combo1.Text
  98. Text2.Text = MyFruit
  99. Call SelectFruit  'synchronize the listbox
  100. End Sub
  101. Sub Command1_Click ()
  102. Call SetTabStops
  103. End Sub
  104. Sub Command2_Click ()
  105. Unload Form1
  106. End Sub
  107. Sub Form_Load ()
  108. Dim F As Integer
  109. 'load up some multi-column data
  110. Text1.Text = "Fruit" + Chr$(9) + "Opinion" + Chr$(9) + "Color"
  111. Fruit(1) = "Oranges" + Chr$(9) + "Good" + Chr$(9) + "Orange, of course"
  112. Fruit(2) = "Bananas" + Chr$(9) + "Munchy" + Chr$(9) + "Yellow"
  113. Fruit(3) = "Apples" + Chr$(9) + "Delicious" + Chr$(9) + "Red"
  114. Fruit(4) = "Blueberries" + Chr$(9) + "Nah" + Chr$(9) + "Blue"
  115. Fruit(5) = "Plums" + Chr$(9) + "Better than prunes" + Chr$(9) + "Purple"
  116. Fruit(6) = "Watermelons" + Chr$(9) + "Marvelous" + Chr$(9) + "Red and Green"
  117. Fruit(7) = "Cherries" + Chr$(9) + "Ummm..." + Chr$(9) + "Bright Red"
  118. Fruit(8) = "Mangos" + Chr$(9) + "Juicy" + Chr$(9) + "No idea"
  119. Fruit(9) = "Kiwis" + Chr$(9) + "Kinda weird" + Chr$(9) + "Fuzzy Green"
  120. Fruit(10) = "Peaches" + Chr$(9) + "OK" + Chr$(9) + "Peach, I guess(?)"
  121. For F = 1 To UBound(Fruit)
  122.    List1.AddItem Fruit(F)
  123.    'comboboxes don't support columns, so only use first string
  124.    Combo1.AddItem Left$(Fruit(F), InStr(Fruit(F), Chr$(9)) - 1)
  125. For F = 0 To Screen.FontCount - 1
  126.    List2.AddItem Screen.Fonts(F)
  127. TabStopsSet = True
  128. Command1.Value = True  'trigger tab stops
  129. End Sub
  130. Sub List1_Click ()
  131. MyFruit = List1.Text
  132. If Len(MyFruit) > 0 Then
  133.    MyFruit = Left$(MyFruit, InStr(MyFruit, Chr$(9)) - 1)
  134.    Text2.Text = MyFruit
  135.    Call SelectFruit  'synchronize the combobox
  136. End If
  137. End Sub
  138. Sub List2_Click ()
  139. List1.FontName = List2.List(List2.ListIndex)
  140. List1.Height = (Combo1.Top - List1.Top) - 10
  141. TabStopsSet = Not TabStopsSet
  142. Command1.Value = True  'trigger tab stops
  143. End Sub
  144. Sub SelectFruit ()
  145. If SelectListItem(List1, MyFruit) Then
  146.    If SelectListItem(Combo1, MyFruit) Then
  147.    End If
  148. End If
  149. End Sub
  150. Sub SetTabStops ()
  151. If TabStopsSet Then
  152.    If SetListCols(List1, Text1, False, True) Then
  153.       Command1.Caption = "Set &Custom Tab Stops"
  154.       TabStopsSet = Not TabStopsSet
  155.    End If
  156.    If SetListCols(List1, Text1, False, False) Then
  157.       Command1.Caption = "Reset &Default Tab Stops"
  158.       TabStopsSet = Not TabStopsSet
  159.    End If
  160. End If
  161. End Sub
  162. Sub Text2_Change ()
  163. MyFruit = Text2.Text
  164. Call SelectFruit  'synchronize the listbox and combobox
  165. End Sub
  166.