Quantcast
Channel: Sandstorm's Blog (Home of ssUltimate Library)
Viewing all articles
Browse latest Browse all 160

ComboBox in a Grid - Combobox Trick # 2

$
0
0

I have promised last time I will show another combobox trick but totally forgot about it.  Then yesterday another member asked about a combobox inside a grid saying while it is working on his end, whatever is selected on the active combobox does not appear.  It appears only when the combobox on the current record looses focus.

While working directly with grids do not appeal to me, I played with his requirement and indeed it does not show the combobox' DisplayValue.  So I got curious because if I recall properly, I fixed that problem on my end before but in the end working directly on a Grid does not really appeal to me that I discarded the entire concept and went back to Add To Table approach.

Anyway, here is a working sample of that if you need one, and on the bottom note the reason why:




loTest = Createobject("Sample")
loTest.Show(1)

Define Class Sample As Form
      Caption = 'Combobox in a Grid'
      AutoCenter = .T.
      Width = 240

      Add Object grid1 As Grid WITH ;
      ColumnCount = 1,;
      RowHeight = 22,;
      Width = 220,;
      DeleteMark = .F.

      Procedure Load
            Set Autoincerror Off
            Close Databases All
            Create Cursor junkdata (jdpk I Autoinc, prodfk I)
            For lnloop = 1 To 5
                  Append Blank
            Next
            Go Top

            Create Cursor junkproduct (prodpk I Autoinc, products c(30))
            Insert Into junkproduct Values (0,'Coke')
            Insert Into junkproduct Values (0,'Pepsi')
            Insert Into junkproduct Values (0,'Sprite')
            Insert Into junkproduct Values (0,'Mirinda')
            Insert Into junkproduct Values (0,'Royal')
            Insert Into junkproduct Values (0,'7-Up')
      Endproc

      Procedure grid1.Init
            With This
                  .RecordSourceType =1
                  .RecordSource = 'junkdata'
                  With .Column1
                      .Width = 200
                        .ControlSource = 'junkdata.prodfk'
                        .AddObject('Combo1','MyCombo')
                        .CurrentControl = 'Combo1'
                        .Combo1.Visible = .T.
                        .Sparse = .F.
                  Endwith
            Endwith
      Endproc

Enddefine

Define Class MyCombo As ComboBox
      RowSourceType = 2
      BoundColumn = 2
      BoundTo = .F.
      RowSource = 'junkproduct.products,prodpk'
      Value = 0
      Style = 2
      ControlSource = 'junkdata.prodfk'
Enddefine


See that it is showing the proper DisplayValue on the active combobox immediately after you selected on its dropdown portion?  Well the problem, AFAIK, is about the .BoundTo property.  While I mostly preferred it to be set to .T., in this case it is giving that adverse effect of hiding what has been selected in the dropdown portion when it disappears so it should be set to .F..

Study the sample and Enjoy!



Viewing all articles
Browse latest Browse all 160

Trending Articles