Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Marcia Akins
  Where is Marcia Akins?
 Akorn
 Ohio - United States
 Marcia Akins
 To: Rob Vleeschhouwer
  Where is Rob Vleeschhouwer?
 Leeuwarden
 Netherlands
 Rob Vleeschhouwer
 Tags
Subject: RE: Incremental search
Thread ID: 104192 Message ID: 104225 # Views: 3 # Ratings: 1
Version: Visual FoxPro 9 Category: Grids
Date: Sunday, August 13, 2006 3:04:27 PM         
   


In a listbox with incremental search VFP seeks only in the first column. Even when
the index is set to a field in another column. Is there no way to force VFP to search on another column(fiedl)? Or is it better to use a utility as, p.e. Jkey


Use a grid instead. You can make it look like a litbox and sort the grid when you click on a column header. Code like this in the grid's Init to set it up"

*** now make sure that the dblclick method of all the contained text boxes
*** delegate to the grid's dblclick()
FOR EACH loColumn IN This.Columns
  FOR EACH loControl IN loColumn.CONTROLS
    IF LOWER( loControl.BASECLASS ) = 'header'
      *** If the column is sortable, make the header font italic
      lcField = JUSTEXT( loColumn.ControlSource )      
      *** This causes a crash if the cursor
      *** for the grid's record source isn't built yet
      IF USED( THIS.RECORDSOURCE )
	*** IsTag just returns .T. or .F. if there
	*** is an index tag on this field
        IF IsTag( lcField, THIS.RECORDSOURCE )
          loControl.FONTITALIC = .T.
        ENDIF
      ENDIF
      BINDEVENT( loControl, 'Click', THIS, 'SortGrid' )
    ELSE
      IF PEMSTATUS( loControl, [dblClick], 5 )
        BINDEVENT( loControl, 'dblClick', THIS, 'dblClick' )
      ENDIF
    ENDIF
  ENDFOR
ENDFOR


This code in SortGrid()

*** First of all, see which column fired off this event
AEVENTS( laEvents, 0 )
loHeader = laEvents[ 1 ]
IF VARTYPE( loHeader ) = 'O'
  *** First See if a ControlsSource was set for the column
  lcField = JUSTEXT( loHeader.Parent.ControlSource )
  This.cSortField = []
  *** we have a field - let's see if it already has a sort order set
  *** if it does, it will have the appropriate picture in the header
  lcSortOrder = ''
  IF NOT EMPTY( loHeader.Picture )
    lcSortOrder = IIF( LOWER( JUSTFNAME( loHeader.Picture ) ) == 'down.bmp', '', 'DESC' )
  ELSE
    *** See if there is a visual cue on any of the other grid
    *** column headers and remove it if there is
    FOR EACH loColumn IN This.Columns
      FOR EACH loControl IN loColumn.Controls
        IF LOWER( loControl.BaseClass ) == [header]
          IF NOT EMPTY( loControl.Picture )
            llFoundColumn = .T.
            loControl.Picture = []
            loControl.FontBold = .F.
            EXIT
          ENDIF
        ENDIF
      ENDFOR
      IF llFoundColumn
        EXIT
      ENDIF
    ENDFOR
  ENDIF
  
  *** if we have a field - let's sort
  IF NOT EMPTY( lcField )
    *** There seems to be a refresh issue here
    *** because even though the data is in the cursor
    *** it is not showing up in the grid after the sort
    *** and it looks like it is related to AllowCellSelection being .F.
    This.AllowCellSelection = .F.
    This.Refresh()
    KEYBOARD '{CTRL+TAB}'
    
    *** Check to see if the tag exists assume
    *** that if there is a tag on this field, it has the same name as the field
    IF IsTag( lcField, This.RecordSource )
      This.cSortField = lcField
      lnRecNo = RECNO( This.RecordSource )
      *** Go ahead and set the order for the table
      SELECT ( This.RecordSource )
      IF NOT EMPTY( lcSortOrder )
        SET ORDER TO ( lcField ) DESCENDING 
      ELSE
        SET ORDER TO ( lcField ) 
      ENDIF
      This.SetFocus()
      IF lnRecNo # 0
        GO lnRecNo IN ( This.RecordSource )
      ENDIF
      *** And set the visual cues on the header
      loHeader.Picture = IIF( EMPTY( lcSortOrder ), [..\graphics\up.bmp], [..\graphics\down.bmp] )
      loHeader.FontBold = .T.
    ENDIF  
  ENDIF
ENDIF
This.AllowCellSelection = llAllowCellSelection


You can then also use BindEvent() to handle the incremental searching and add a method to the grid to handle that.

Regards,
Marcia G. Akins
Tightline Computers, Inc.


ENTIRE THREAD

Incremental search Posted by Rob @ 8/13/2006 12:13:29 AM
RE: Incremental search Posted by Marcia Akins @ 8/13/2006 3:04:27 PM