Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem with combobox in grid

Status
Not open for further replies.

Nifrabar

Programmer
Mar 16, 2003
1,343
NL
Hi!
Happy newyear to all of you.

A grid on a form has parametrized view as rowsource.

In one of the columns I put combobox, so user can choose a value from lookuptable.

All works as expected apart from:

-1-
If I click in the combo than there is just the 'blue' background in the gridcell.
Cannot stay the original value visible in the combo/grid?

-2-
Only I clicked somewhere else in the grid the selcted item pops up in the grid.
Must I do a requery (remember the grids controlsource is parametrized view) If yes, where to put the requery command? In a combo-method or in a grid method?

TIA
-Bart


 
Hi,

Happy New Year to you as well.

Try it again with the Sparse property set to .F.

Groet,
Jockey(2)
 
Here is a sample for implementing combo in grid:

Code:
*!*	Combobox in a grid column sample
*!*	Author:Cetin Basoz

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

Define Class comboingrid As Form
  Top = 0
  Left = 0
  Height = 350
  Width = 620
  DataSession=2

  Add Object grdorditems As Grid With ;
    Height = 300, ;
    Left = 10, ;
    Top = 10, ;
    Width = 600, ;
    Rowheight = 19,;
    RecordSource = "orditems"

  Procedure Load
    Use _samples+'Data\products' In 0
    Use _samples+'Data\orditems' In 0 Order Tag order_id
    Set Multilocks On
    CursorSetProp("Buffering",5,'orditems') && we don't want to save edits in test mode
  Endproc

  Procedure grdorditems.Init
    Local ix
    With This
      For ix = 1 To .ColumnCount
        If Upper(Justext(.Columns(m.ix).ControlSource)) == 'PRODUCT_ID'
          With .Columns(m.ix)
            .Bound = .F.
            .ControlSource = "(Iif(Seek(orditems.product_id,"+;
              "'products','product_id'),Products.prod_name,''))"
            .Width = 170
            .AddObject('comboincol','combobox')
            With .ComboIncol
              .BoundColumn = 2
              .BoundTo = .T.
              .ColumnCount = 2
              .ColumnWidths = "180,0"
              .RowSourceType = 3
              .RowSource = "select products.prod_name,product_id, unit_price"+;
                " from products into cursor crsProducts order by 1"
              .SpecialEffect = 1
              .Style = 2
              .ControlSource = "orditems.product_id"
              .Visible = .T.
            Endwith
            .CurrentControl = 'comboincol'
          Endwith
          Exit
        Endif
      Endfor
    Endwith
  Endproc

  Procedure grdorditems.BeforeRowColChange
    Lparameters nIndex
    If Type('this.Columns(m.nIndex).ComboInCol') = 'O' && Column with combo we added
      Select (This.RecordSource)
      Replace unit_price With crsProducts.unit_price
      This.Refresh()
    Endif
  Endproc
Enddefine


Cetin Basoz
MS Foxpro MVP, MCP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top