home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Programming Tool Box
/
SIMS_2.iso
/
code
/
design
/
lbtabs
/
listdemo.txt
< prev
Wrap
Text File
|
1995-02-26
|
5KB
|
170 lines
Option Explicit
'Updated 01/06/95 - DULIST.BAS Fixes and Enhancements
'
' dulist_tfSetListCols
' --------------------
' Fixed bug that caused an endless
' loop if the last character of a
' listbox item string was a Chr$(9) tab.
'
' dulist_sGetColumn
' -----------------
' New routine to extract data, by column,
' from a tab-delimited string.
'
' dulist_AddHorizScrollBar
' ------------------------
' New routine to add a horizontal
' scrollbar to a listbox.
'If you have questions, comments, or suggestions for
'improving the code presented here, please forward them
'to me; your input is welcome:
'
' Brad Kaenel
' PC HELP-LINE
' 35250 Silver Leaf Circle
' Yucaipa, CA 92399
' United States
' CIS: 72357,3523
' Internet: 72357.3523@compuserve.com
'
'Although multi-column listboxes are a common
'requirement, they are difficult to accomplish
'in VB.
'A simple solution is to select a mono-spaced
'font for the listbox and align the data manually,
'but this is not always visually appealing. However,
'with a little more work you can set dynamic tabstops
'that will work with proportional fonts.
'This sample demonstrates how to set tabstops in a listbox,
'using a borderless, disabled text box for the column
'headings. It also shows how to "pre-select" a listbox
'or combobox item, using Windows API functions.
Dim sFruit(10) As String, sMyFruit As String
Dim nTabStopsSet As Integer
Sub cboSelect_Click ()
sMyFruit = cboSelect.Text
txtSearch.Text = sMyFruit 'synchronize the textbox
Call SelectFruit 'synchronize the listbox
End Sub
Sub cmdExit_Click ()
Unload frmListDemo
End Sub
Sub cmdSetColumns_Click ()
Call SetTabStops
End Sub
Sub Form_Load ()
Dim nFruitCount As Integer
Dim sTAB As String
sTAB = Chr$(9)
'add a horiz scrollbar
Call dulist_AddHorizScrollBar(lstFruits, 0)
'load up some multi-column data
txtListHeadings.Text = "Fruit" + sTAB + "Opinion" + sTAB + "Color"
sFruit(1) = "Oranges" + sTAB + "Good" + sTAB + "Orange, of course"
sFruit(2) = "Bananas" + sTAB + "Munchy" + sTAB + "Yellow"
sFruit(3) = "Apples" + sTAB + "Delicious" + sTAB + "Red"
sFruit(4) = "Blueberries" + sTAB + "Nah" + sTAB + "Blue"
sFruit(5) = "Plums" + sTAB + "Better than prunes" + sTAB + "Purple"
sFruit(6) = "Watermelons" + sTAB + "Marvelous" + sTAB + "Red and Green"
sFruit(7) = "Cherries" + sTAB + "Ummm..." + sTAB + "Bright Red"
sFruit(8) = "Mangos" + sTAB + "Juicy" + sTAB + "No idea"
sFruit(9) = "Kiwis" + sTAB + "Kinda weird" + sTAB + "Fuzzy Green"
sFruit(10) = "Peaches" + sTAB + "OK" + sTAB + "Peach, I guess(?)"
For nFruitCount = 1 To UBound(sFruit)
lstFruits.AddItem sFruit(nFruitCount)
'comboboxes don't support tabstops, so use only the first column string
cboSelect.AddItem dulist_sGetColumn(sFruit(nFruitCount), 1)
Next
For nFruitCount = 0 To Screen.FontCount - 1
lstFonts.AddItem Screen.Fonts(nFruitCount)
Next
nTabStopsSet = True
cmdSetColumns.Value = True 'trigger tab stops
End Sub
Sub lstFonts_Click ()
lstFruits.FontName = lstFonts.List(lstFonts.ListIndex)
lstFruits.Height = (lstFonts.Top - lstFruits.Top) - 20
nTabStopsSet = Not nTabStopsSet
cmdSetColumns.Value = True 'trigger tab stops
End Sub
Sub lstFruits_Click ()
sMyFruit = dulist_sGetColumn((lstFruits.List(lstFruits.ListIndex)), 1)
txtSearch.Text = sMyFruit 'synchronize the textbox
Call SelectFruit 'synchronize the combobox
End Sub
Sub SelectFruit ()
If dulist_tfSelectListItem(lstFruits, sMyFruit) Then
If dulist_tfSelectListItem(cboSelect, sMyFruit) Then
End If
End If
End Sub
Sub SetTabStops ()
If nTabStopsSet Then
If dulist_tfSetListCols(lstFruits, txtListHeadings, False, True) Then
cmdSetColumns.Caption = "Set &Custom Tab Stops"
nTabStopsSet = Not nTabStopsSet
End If
Else
If dulist_tfSetListCols(lstFruits, txtListHeadings, False, False) Then
cmdSetColumns.Caption = "Reset &Default Tab Stops"
nTabStopsSet = Not nTabStopsSet
End If
End If
End Sub
Sub txtSearch_Change ()
sMyFruit = txtSearch.Text
Call SelectFruit 'synchronize the listbox
'and the combobox
End Sub