Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Combo box in a grid
Message
From
23/05/2001 07:56:21
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
23/05/2001 07:39:09
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Miscellaneous
Thread ID:
00510254
Message ID:
00510259
Views:
15
>Hi.
>I have a grid in which in one of the columns I need a combo or list box that works as follows:
>1.- Lists all values previously entered in the field;
>2.- Shows no duplicate values
>3.- When an item in the combo/list is selected, its added in the new record, or changed in a previous record;
>4.- Allows the user to enter a new value if no similar value had been entered before.This new value should be added to the record and shown in the list immediately if a new record is needed.
>
>I tried a Select-Distinct-SQL statement in a combo box, but this won't allow me to add a new value.
>What properties should I set to achieve this result?
>TIA
>Ulises.

Ulises,
I hope this helps :
**************************************************
*-- Class:        cmbself_edit (c:\commonlib\global.vcx)
*-- ParentClass:  combobox
*-- BaseClass:    combobox
*-- Time Stamp:   08/27/98 11:13:08 AM
*
Define CLASS cmbself_edit AS combobox
  Height = 22
  Width = 100
  DisabledBackColor = RGB(255,255,255)
  aliasname = "None"
  fieldname = "None"
  Name = "cmbself_edit"

  Procedure GotFocus
  This.REQUERY							&& Do we have new elements ?
  This.value = eval(this.controlsource)	&& Reposition
Endproc

  Procedure InteractiveChange
  *
  * Self note : Restudy this code
  *
  *This.displayvalue = ;
  * Chrtran(This.displayvalue,"ýi","IÝ") && Local language fix
  With this
    If .selstart = 0
      Return
    Endif
    cPos = .selstart
    If lastkey() = 127 && Backspace
      If .selstart = 1
        .displayvalue = ""
        .selstart = 0
        .sellength = 0
        Return
      Endif
      cCheckValue = left(.displayvalue,.selstart-1)
      cPos = cPos - 1
    Else
      cCheckValue = iif(cPos = 1,"",left(.displayvalue,cPos-1))+chr(lastkey())
    Endif
    lExistsOne = .f.
    For ix = 1 to .listcount
      If  Upper(Alltrim(.list(ix))) = upper(alltrim(cCheckValue))
        .displayvalue = .list(ix)
        lExistsOne = .t.
        Exit
      Endif
    Endfor
    .selstart = cPos
    If lExistsOne         && Available item
      .sellength = len(.displayvalue) - cPos
    Else
      .sellength = 0
    Endif
  Endwith
Endproc

  Procedure LostFocus
  *This.displayvalue = ;
  * Chrtran(This.displayvalue,"ýi","IÝ") && Local language fix
  This.value = this.displayvalue
  This.displayvalue = this.value
Endproc

  Procedure Init
  With This
    .rowsourcetype = 3
    If lower(.fieldname)="none" or ;
        lower(.aliasname)="none" && Lookup is same as controlsource alias
      .fieldname = substr(.controlsource,rat(".",.controlsource)+1)
      .aliasname = substr(.controlsource,1,;
        rat(".",.controlsource)-1)
    Endif
    .rowsource = [SELECT DISTINCT ]+THIS.fieldname +;
      [ as dummy FROM ]+this.aliasname+[ where !empty(]+THIS.fieldname + ;
      [) union ] +;
      [SELECT this.displayvalue as dummy ] +;
      [ FROM ]+this.aliasname + ;
      [ union ] +;
      [SELECT this.value as dummy ] +;
      [ FROM ]+this.aliasname + ;
      [ INTO cursor qq order by 1 ]
    If .parent.baseclass = "Column"
      .parent.sparse = .t.  && Force sparse .t. for grids
    Endif
  Endwith
Endproc

Enddefine
*
*-- EndDefine: cmbself_edit
**************************************************
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform