Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Display text, in Item Tips, in a multiple column List Box

Tips & Tricks

Display text, in Item Tips, in a multiple column List Box

by  Imaginecorp  Posted    (Edited  )
A list box with multiple columns will not display the full text of the Bound Column in Item Tips, if the width of the text is Less than the List Box width.

VFP uses an internal RTRIM() to display the text in an Item Tip. The idea here is to expand the text width to fool VFP into displaying it in Item Tips.

NOTE: this example works with the form Scale Mode set to Pixels, thus the +15 and -20, as FONTMETRIC() is not very accurate. (You may have to play with this.) Foxels will make it much easier, (Use REPLICATE() instead of PADR()).

Caution:
Do not specify a Control Source.
You could, by using STREXTRACT().
If the value is being used to update a field use STREXRACT().

Hover over the text in the list box, column 1, and if the text width is larger than the 1st column width it will display the text in the Item Tips.

Code:
******* VFP9 with SP 1
PUBLIC oform1

oform1=NEWOBJECT("form1")
oform1.Show
RETURN


    **************************************************
*-- Form:         form1 (\imaginecorp\form1.scx)
*-- ParentClass:  form
*-- BaseClass:    form
*-- Time Stamp:   02/01/07 09:50:14 PM
*
DEFINE CLASS form1 AS form


    Top = 3
    Left = 48
    DoCreate = .T.
    Caption = "Show Item Tips..."
    Name = "Form1"


    ADD OBJECT list1 AS listbox WITH ;
        ColumnCount = 2, ;
        ColumnWidths = "140,70", ;
        Height = 179, ;
        Left = 45, ;
        Top = 27, ;
        Width = 236, ;
        ItemTips = .T., ;
        Name = "List1"


    ADD OBJECT command1 AS commandbutton WITH ;
        Top = 218, ;
        Left = 281, ;
        Height = 27, ;
        Width = 84, ;
        Caption = "Close", ;
        Name = "Command1"


    ADD OBJECT label1 AS label WITH ;
        AutoSize = .T., ;
        Caption = "Company", ;
        Height = 17, ;
        Left = 51, ;
        Top = 10, ;
        Width = 55, ;
        Name = "Label1"


    ADD OBJECT label2 AS label WITH ;
        Caption = "ID", ;
        Height = 17, ;
        Left = 196, ;
        Top = 10, ;
        Width = 40, ;
        Name = "Label2"


    PROCEDURE Load
        If Used("customer")
            Use In customer
        Endif
        Select 0
        Use Home()+"samples\data\customer.dbf"
    ENDPROC


    PROCEDURE list1.Init
        Local nFontSize,nFieldWidth,nFirstColumn

        Select customer

        nFontSize = Fontmetric(6,Thisform.list1.FontName,Thisform.list1.FontSize)
        nFieldWidth = Thisform.list1.Width-(Fsize("company","customer")* nFontSize)
        nFirstColumn = Val(Strextract(Thisform.list1.ColumnWidths,"",",",1))

        Select ICASE((Len(Alltrim(customer.company))* nFontSize) >= (nFirstColumn-20),;
            Padr(customer.company,(nFieldWidth+15),".") ,customer.company) as company ,;
            customer.cust_id ;
            FROM customer ;
            INTO Cursor custcursor
        With This
            .ItemTips = .T.
            .RowSource = "custcursor.company,cust_id"
            .rowsourcetype = 6
            .Value = .TopIndex
        Endwith
    ENDPROC


    PROCEDURE command1.Click
        USE IN customer
        thisform.release
    ENDPROC


ENDDEFINE
*
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top