Thursday, July 5, 2012

Grid Trick# 5 - Column Moved or Header Simply Clicked?

A question inside foxite is raised just now and it took my fancy on trying to find out how to differentiate if user simply clicks on the header of a column or has moved it.  Until I realize I was looking at the wrong things because really it comes only with two simple rules:

  1. If you wanted to do something when you click the header, then use header's click event
  2. If you wanted to do something when you reposition column, then use column's moved event
Here is a simple sample for that:

Local oForm
Read Events

Define Class Form1 As Form
    Height = 390
    Width = 500
    AutoCenter = .T.
    Caption = 'Column Moved or Header Simply Clicked?'

    Add Object grid1 As Grid With ;
        GridLines = 0, ;
        Height = 328, ;
        Left = 10, ;
        Top = 50, ;
        Width = 480,;
        GridLines = 3,;
        DeleteMark = .F.,;
        GridLineColor = Rgb(192,192,192),;
        FontName = 'Tahoma',;
        FontSize = 8, Anchor = 15, AllowCellSelection = .F.

    Procedure Load
        Set Talk Off
        Set Safety Off
        Close Databases All
        Select  company,contact,Title From (Home(2)+"data\customer") Where Recno() < 50 Into Cursor junk
        Use In Select('customer')

    Procedure grid1.Init
        With This
            .RecordSourceType = 6
            .RecordSource = 'junk'
            .Column1.Header1.Caption = 'Column1'
            .Column2.Header1.Caption = 'Column2'
            .Column3.Header1.Caption = 'Column3'
            For lnloop = 1 To .ColumnCount

    Procedure _Moved

    Procedure Destroy
        Clear Events


No comments:

Post a Comment