Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Combobox woes
Message
De
05/10/2008 08:32:13
 
 
À
04/10/2008 11:38:18
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
Versions des environnements
Visual FoxPro:
VFP 9 SP1
OS:
Vista
Network:
Windows 2008 Server
Database:
MS SQL Server
Divers
Thread ID:
01352729
Message ID:
01352846
Vues:
86
This message has been marked as the solution to the initial question of the thread.
However -- if I have made a typo, such as entering TA instead of TZ, I cannot backspace to eliminate the A, so that I can re-enter the Z. I would expect to be able to enter

'T', 'A', Backspace, 'Z' and see the same effect as having types 'T', 'Z'.
**************************************************
*-- Class:        cboaliasqfill 
*-- ParentClass:    combobox
*-- Time Stamp:   08/07/07 05:08:13 PM
*-- Variation of quickfill combo that works on a specified alias
*
Define Class cboaliasqfill As combobox

  Height = 22
  SelectOnEntry = .T.
  Style = 0
  Width = 120
  coldexact = ""
  *-- Alias used as the RowSource for the combo
  calias = ""
  *-- Tag to use when trying to find a match for what was typed in so far
  ctag = ""
  *-- Name of field to search....Populated by combo in its SetCombo mathod
  ckeyfield = ""
  *-- When true, allows a new entry to be added
  lallowaddnew = .F.
  *-- XML Metadata for customizable properties
  _MemberData = [<VFPData><memberdata name="lallowaddnew" type="property" display="lAllowAddNew"/></VFPData>]
  Name = "cboaliasqfill"


  Procedure handlekey
    Lparameters tnKeyCode
    Local lcSofar, lnSelStart, lnSelLength, lnSelect, lcFld

    With This
      *** Handle backspace key
      If tnKeyCode = 127
        If .SelStart = 0
          Return .F.
        Endif
        .SelStart = .SelStart - 1
        lnSelStart = .SelStart
        lcSofar =  Upper( Left( .DisplayValue, lnSelStart ) )
      Else
        *** Get the value typed in so far
        lnSelStart = .SelStart+1
        lcSofar =  Upper( Left( .DisplayValue, .SelStart ) + Chr( tnKeyCode ) )
      Endif
      *** See if we can find a match in the Alias used as the RowSource
      lcFld = .calias + '.' + .ckeyfield
      If !Empty( .ctag )
        If Seek( lcSofar, .calias, .ctag )
          .DisplayValue = Eval( lcFld )
        Else
          If Not This.lallowaddnew
            .ListIndex = 0
            lnSelStart = 0
          Else
            Return .F.
          Endif
        Endif
      Else
        lnSelect = Select()
        Select ( .calias )
        Locate For Upper( &lcFld ) = lcSofar
        If Found()
          .DisplayValue = Eval( lcFld )
        Else
          If Not This.lallowaddnew
            .ListIndex = 0
            lnSelStart = 0
          Else
            Return .F.
          Endif
        Endif
        Select ( lnSelect )
      Endif
      *** Highlight the portion of the value after the insertion point
      .SelStart = lnSelStart
      lnSelLength = Len( Alltrim( .DisplayValue ) ) - lnSelStart
      If lnSelLength > 0
        .SelLength =  lnSelLength
      Endif
    Endwith
  Endproc


  Procedure setcombo
    With This
      *** First of all, make sure that we have either a RowSourceType of 2 or 4
      If ! Inlist( .RowSourceType, 2, 6 )
        Assert .F. Message .Name + ': RowSourceType MUST be either 2 or 6'
        Return .F.
      Endif
      *** Since RowSOurceType of 2-Alias can beused just like 6-Fields and
      *** fields can be specified in the RowSource, let's just get the alias name
      *** The following returns the alias name in both cases:
      *** if alias.field,field,field is specified or if only an alias is specified
      .calias = Juststem( .RowSource )
      *** Now check to see if the user specified fields
      If Empty( Justext( .RowSource ) )
        *** Means no fields were specified...this better be a RowSourceType of 2-Alias
        If .RowSourceType = 2
          .ckeyfield = Field( 1, .calias )
        Else
          Assert .F. Message .Name + ': You MUST specify a field list when using a RowSourceType of 6'
          Return .F.
        Endif
      Else
        *** Parse out the first field
        Local lcRest, lnCommaPos
        lcRest = Justext( .RowSource )
        lnCommaPos = At( ',', lcRest )
        .ckeyfield = Iif( lnCommaPos = 0, lcRest, Left( lcRest, lnCommaPos - 1 ) )
      Endif
      *** Set the cTag property
      .ctag = Order( .calias )
    Endwith
  Endproc


  Procedure Init
    If !This.setcombo()
      Return .F.
    Endif
  Endproc


  Procedure GotFocus
    ComboBox::GotFocus()
    With This
      .uOldVal = This.Value
      .coldexact = Set( 'EXACT' )
      .SelStart = 0
      .SelLength = Len( .Text )
    Endwith
    Nodefault
  Endproc


  Procedure LostFocus
    If This.coldexact = 'ON'
      Set Exact On
    Endif
  Endproc


  Procedure KeyPress
    Lparameters nKeyCode, nShiftAltCtrl
    *** handle the key...IOW, find the closest match in the list
    If ( nKeyCode > 31 And nKeyCode < 128 ) Or ( nKeyCode = 7 )
      *** We need this to update the combo's display value
      If This.handlekey( nKeyCode )
        Nodefault
      Endif
    Endif
  Endproc
Enddefine
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform