none
Combo not display the value in grid (When Focused)

    Question

  • What RESOLVING this problem???

     

    Based in KB138779 example, but fields Friends.State and States.Abbrev are altered by Integer.

     

    1.  Create two tables by using the following commands:

    o       CREATE TABLE Friends (Name C(40), Address C(30), State I)

    o       CREATE TABLE States (Fullname C(20), Abbrev I)

    2.  Enter the following data in the States table:

          Full Name    Abbreviation

          -------------------------

     

          Alaska       2

          Colorado     4

          Florida      6

          Idaho        1

          Maine        3

          Ohio         5

          Texas        7

    3.  Enter five records into the Friends table using State Abbrev identify from the States table.

    4.  Create a new form, and add the Friends and States tables to the data environment.

    5.  Drag the Friends table from the data environment to the form to create a grid.

    6.  Set the following properties for the grid:

          ColumnCount = 3

          Height = 200

          Width = 448

          RowHeight = 30

    7.  Right-click the grid, and click Edit. Select the ComboBox control from the Form Controls toolbar and place a combo box in the third column of the grid.

    8.  Set the following Properties for each column in the grid:

          Column1: ControlSource = Friends.Name

                   Width = 152

          Column2: ControlSource = Friends.Address

                   Width = 166

          Column3: ControlSource = Friends.State

                   Bound = .F.

                   Width = 93

                   CurrentControl = Combo1

    9.  Set the following Properties for the combo box in column 3:

          BoundColumn = 2

          BoundTo = .T.

          ColumnCount = 2

          ColumnWidths = 75,0

          ControlSource = Friends.State

          RowSourceType = 6-Fields

          RowSource = States.Fullname,Abbrev

          Style = 2 - Dropdown List

    10. Enter the following code in the GotFocus event of the combo box (This isn’t necessaries):

          IF ! EMPTY(Friends.State)

            This.Value = Friends.State

          ENDIF

    11. In the Init event of the form, enter the following line of code:

           ON KEY LABEL F10 APPEND BLANK IN Friends

           ** Allows you to enter new records in the Grid.

    12. In the Destroy event of the form, enter the following line of code:

           ON KEY LABEL F10

    13. Save and run the Form.

     

     

    Tuesday, December 16, 2008 5:02 PM

Answers

  • This is a sligltly modified version of your steps:

    Code Snippet

    Public oForm
    oForm = Createobject('mytest')
    oForm.Show

    Define Class myTest As Form
      DataSession = 2
      Height = 200
      Width = 448
      KeyPreview = .T.

      Add Object grdFriends As Grid With ;
        recordsource='Friends',Height=200,Width=448,RowHeight=30,ColumnCount=3

     

      Procedure Load
        Create Cursor Friends (Name C(40), Address C(30), State I)
        Create Cursor States (FullName C(20), Abbrev I)

        Insert Into States Values ('Alaska  ',     2)
        Insert Into States Values ('Colorado',     4)
        Insert Into States Values ('Florida ',     6)
        Insert Into States Values ('Idaho   ',     1)
        Insert Into States Values ('Maine   ',     3)
        Insert Into States Values ('Ohio    ',     5)
        Insert Into States Values ('Texas   ',     7)
        Index On Abbrev Tag Abbrev
        Rand(-1)
        For ix = 1 To 5
          Insert Into Friends Values ('Friend'+Padl(m.ix,2), '', Int(Rand()*6)+1)
        Endfor
        Select Friends
        Locate
      Endproc

     

      Procedure Init
        With This.grdFriends
          With .Columns(1)
            .ControlSource = 'Friends.Name'
            .Width = 152
          Endwith
          With .Columns(2)
            .ControlSource = 'Friends.Address'
            .Width = 166
          Endwith
          With .Columns(3)
            .ControlSource = ;
              "(IIF(SEEK(Friends.State,'States','Abbrev'),states.fullname,''))"
            .Bound = .F.
            .AddObject('combo1','combobox')
            With .Combo1
              .BoundColumn = 2
              .BoundTo = .T.
              .ColumnCount = 1
              .ControlSource = 'Friends.State'
              .RowSourceType = 6
              .RowSource = 'States.Fullname,Abbrev'
              .Style = 2
              .Visible = .T.
            Endwith
            .Width = 93
            .CurrentControl = 'combo1'
          Endwith
        Endwith
      Endproc

     

      Procedure KeyPress
        Lparameters nKey,nShift
        If m.nKey = -4 && F5
          Nodefault
          Insert Into Friends (Name) Values ('')
        Endif
      Endproc
    Enddefine

     

     

    Tuesday, December 16, 2008 6:03 PM

All replies

  • 1. Delete Object ....Column3.Text1
    2. Thisform.yourgird.Column3.Sparse  = .f.
    Tuesday, December 16, 2008 5:56 PM
  • This is a sligltly modified version of your steps:

    Code Snippet

    Public oForm
    oForm = Createobject('mytest')
    oForm.Show

    Define Class myTest As Form
      DataSession = 2
      Height = 200
      Width = 448
      KeyPreview = .T.

      Add Object grdFriends As Grid With ;
        recordsource='Friends',Height=200,Width=448,RowHeight=30,ColumnCount=3

     

      Procedure Load
        Create Cursor Friends (Name C(40), Address C(30), State I)
        Create Cursor States (FullName C(20), Abbrev I)

        Insert Into States Values ('Alaska  ',     2)
        Insert Into States Values ('Colorado',     4)
        Insert Into States Values ('Florida ',     6)
        Insert Into States Values ('Idaho   ',     1)
        Insert Into States Values ('Maine   ',     3)
        Insert Into States Values ('Ohio    ',     5)
        Insert Into States Values ('Texas   ',     7)
        Index On Abbrev Tag Abbrev
        Rand(-1)
        For ix = 1 To 5
          Insert Into Friends Values ('Friend'+Padl(m.ix,2), '', Int(Rand()*6)+1)
        Endfor
        Select Friends
        Locate
      Endproc

     

      Procedure Init
        With This.grdFriends
          With .Columns(1)
            .ControlSource = 'Friends.Name'
            .Width = 152
          Endwith
          With .Columns(2)
            .ControlSource = 'Friends.Address'
            .Width = 166
          Endwith
          With .Columns(3)
            .ControlSource = ;
              "(IIF(SEEK(Friends.State,'States','Abbrev'),states.fullname,''))"
            .Bound = .F.
            .AddObject('combo1','combobox')
            With .Combo1
              .BoundColumn = 2
              .BoundTo = .T.
              .ColumnCount = 1
              .ControlSource = 'Friends.State'
              .RowSourceType = 6
              .RowSource = 'States.Fullname,Abbrev'
              .Style = 2
              .Visible = .T.
            Endwith
            .Width = 93
            .CurrentControl = 'combo1'
          Endwith
        Endwith
      Endproc

     

      Procedure KeyPress
        Lparameters nKey,nShift
        If m.nKey = -4 && F5
          Nodefault
          Insert Into Friends (Name) Values ('')
        Endif
      Endproc
    Enddefine

     

     

    Tuesday, December 16, 2008 6:03 PM
  •  Vladimir Zografski wrote:
    1. Delete Object ....Column3.Text1
    2. Thisform.yourgird.Column3.Sparse  = .f.

     

    The problem isn´t resolved.

     

    Thank´s.

     

    Tuesday, December 16, 2008 6:06 PM
  • No need to remove Text1. It has no harm to you but sometimes works to your benefit as shown in code. Did you try the code? Key point is the controlsources of Column3 and Combo1 (and Sparse = .t. default).

    Tuesday, December 16, 2008 6:11 PM
  •  CetinBasoz wrote:

    This is a sligltly modified version of your steps:

    Code Snippet

    Public oForm
    oForm = Createobject('mytest')
    oForm.Show

    Define Class myTest As Form
      DataSession = 2
      Height = 200
      Width = 448
      KeyPreview = .T.

      Add Object grdFriends As Grid With ;
        recordsource='Friends',Height=200,Width=448,RowHeight=30,ColumnCount=3

     

      Procedure Load
        Create Cursor Friends (Name C(40), Address C(30), State I)
        Create Cursor States (FullName C(20), Abbrev I)

        Insert Into States Values ('Alaska  ',     2)
        Insert Into States Values ('Colorado',     4)
        Insert Into States Values ('Florida ',     6)
        Insert Into States Values ('Idaho   ',     1)
        Insert Into States Values ('Maine   ',     3)
        Insert Into States Values ('Ohio    ',     5)
        Insert Into States Values ('Texas   ',     7)
        Index On Abbrev Tag Abbrev
        Rand(-1)
        For ix = 1 To 5
          Insert Into Friends Values ('Friend'+Padl(m.ix,2), '', Int(Rand()*6)+1)
        Endfor
        Select Friends
        Locate
      Endproc

     

      Procedure Init
        With This.grdFriends
          With .Columns(1)
            .ControlSource = 'Friends.Name'
            .Width = 152
          Endwith
          With .Columns(2)
            .ControlSource = 'Friends.Address'
            .Width = 166
          Endwith
          With .Columns(3)
            .ControlSource = ;
              "(IIF(SEEK(Friends.State,'States','Abbrev'),states.fullname,''))"
            .Bound = .F.
            .AddObject('combo1','combobox')
            With .Combo1
              .BoundColumn = 2
              .BoundTo = .T.
              .ColumnCount = 1
              .ControlSource = 'Friends.State'
              .RowSourceType = 6
              .RowSource = 'States.Fullname,Abbrev'
              .Style = 2
              .Visible = .T.
            Endwith
            .Width = 93
            .CurrentControl = 'combo1'
          Endwith
        Endwith
      Endproc

     

      Procedure KeyPress
        Lparameters nKey,nShift
        If m.nKey = -4 && F5
          Nodefault
          Insert Into Friends (Name) Values ('')
        Endif
      Endproc
    Enddefine

     

     

     

    THIS IS A REAL SOLUTION!!!

     

    Thank's.

    Tuesday, December 16, 2008 6:36 PM
  •  CetinBasoz wrote:

    No need to remove Text1. It has no harm to you but sometimes works to your benefit as shown in code. Did you try the code? Key point is the controlsources of Column3 and Combo1 (and Sparse = .t. default).

     

    The Sparse = .T. is obrigatory? But Sparse = .F. the problem return.

    Tuesday, December 16, 2008 6:39 PM
  •  Endrigo Fantastsoft wrote:

    What RESOLVING this problem???

     

    9.  Set the following Properties for the combo box in column 3:

          BoundColumn = 2

          BoundTo = .T.

          ColumnCount = 2

          ColumnWidths = 75,0

          ControlSource = Friends.State

          RowSourceType = 6-Fields

          RowSource = States.Fullname,Abbrev

          Style = 2 - Dropdown List

     

    Change the RowSourceType of the combo to 3-SQL Statement and put the SQL statement in the RowSOurce. This is a known issue with combos in grids when the style is 2-dropdown list and the RowSourceType is 2 or 6.

    Thursday, December 18, 2008 3:33 PM
  • Change the RowSourceType of the combo to 3-SQL Statement and put the SQL statement in the RowSOurce. This is a known issue with combos in grids when the style is 2-dropdown list and the RowSourceType is 2 or 6.

     

    I don't use VFP databases or free tables, i'm use a various RDMS's with CursorAdapter, but thank's your solution. Te real solution to my case is the post of CetinBasoz.

     

    Thursday, December 18, 2008 5:25 PM
  • The Solution is:
    In When combobox:
    This.Parent.Sparse = .T.
    In LostFocus  combobox:
    This.Parent.Sparse = .F.
    Thursday, June 25, 2009 12:54 PM