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!

VFP9: unable to connect combo from grid to datafield

Status
Not open for further replies.

Eliott

Programmer
Nov 8, 2009
91
BA
Hi, by following some advices

Code:
WITH THIS
 .column3.ControlSource = "cars" &&table of Grid1
 .column3.AddObject("cmbKodna","combobox")
 .column3.CurrentControl = "cmbKodna"
 .column3.cmbKodna.AddItem("1")
 .column3.cmbKodna.AddItem("2")
 .column3.cmbKodna.AddItem("3")
 .column3.cmbKodna.AddItem("122")
 .column3.cmbKodna.AddItem("407")
 .column3.cmbKodna.AddItem("505")
 .column3.cmbKodna.AddItem("707")
 .column3.cmbKodna.AddItem("747")
 .column3.Sparse = .F.
 .column3.cmbKodna.style=2 && dropdown listbox
 .Visible= .T.
 ENDWITH

from this forum I was able to put combo inside one column of Grid. Combo style is 2 and Rowsourcetype is 1 (Value). I would like to be able to remember in proper data field of used table from Grid a value I picked from mentioned Combo. Do I need add ControlSource for this Combo to wished data field?
Thank you.

There is no good nor evil, just decisions and consequences.
 
np, but you should have:
.column3.cmbKodna.Visible = .t.
Also check BoundTo property.

Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
Hi Mr. Borislav, thank you. I inserted:
Code:
WITH THIS
 .column3.ControlSource = "cars" &&table of Grid1
 .column3.AddObject("cmbKodna","combobox")
 .column3.CurrentControl = "cmbKodna"
 .column3.cmbKodna.AddItem("1")
 .column3.cmbKodna.AddItem("2")
 .column3.cmbKodna.AddItem("3")
 .column3.cmbKodna.AddItem("122")
 .column3.cmbKodna.AddItem("407")
 .column3.cmbKodna.AddItem("505")
 .column3.cmbKodna.AddItem("707")
 .column3.cmbKodna.AddItem("747")
 .column3.Sparse = .F.
 .column3.cmbKodna.style=2 && dropdown listbox
 .column3.cmbKodna.Visible= .T.
.column3.cmbKodna.boundto=.t.   &&instead .f.
.column3.cmbKodna.Boundcolumn=1
 ENDWITH

and now it's working fine, but each time I started form then first row in Grid1, column3 (where is Combo), has value 0. I change it to correct value by picking from Combo, click anywhere on grid, then exit from form, returned back but always 0! Other rows in column3 kept their values after I changed them! Where is trick? Thank you.

There is no good nor evil, just decisions and consequences.
 
Eliott,

I don't know if this will solve your problem, but there are a couple of points to note:

1. You say: "Combo style is 2 and Rowsourcetype is 1 (Value).". Because you are using .AddItem(), you need the RowSourceType to be 0.

2. .column3.ControlSource should not just be "cars"; it should include both the alias and the field name(for example, "MyTable.Cars" or "Cars.ID").

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Hi Mike, I made change you mentioned
Code:
.column3.ControlSource = "cars.colorcode"
but still got the same problem. :(

There is no good nor evil, just decisions and consequences.
 
Here how I made it:
Code:
CREATE CURSOR crsCars (Name C(20), Model C(20), Color I)
INSERT INTO crsCars VALUES("Ford", "T" , 1)
INSERT INTO crsCars VALUES("Audi", "A8", 2)
GO TOP
BROWSE NORMAL
oForm = CREATEOBJECT("Form1")
oForm.Show(1)
BROWSE NORMAL


DEFINE CLASS Form1 AS Form

PROCEDURE init
***** THIS
    thisform.BindControls = .f.
********
    thisform.NewObject("Grid1","Grid")
    WITH thisform.Grid1 AS Grid
         .Left = 0
         .Top = 0
         .Width = thisform.Width - 2
         .Height = thisform.Height - 2
         .ColumnCount = 3
         .RecordSource = [crsCars]
         .column1.ControlSource = "crsCars.Name"
         .column2.ControlSource = "crsCars.Model"
         .column3.ControlSource = "crsCars.Color"
         .column3.AddObject("cmbKodna","combobox")
         .column3.cmbKodna.Rowsourcetype = 1
         .column3.CurrentControl = "cmbKodna"
         .column3.RemoveObject("Text1")
         .column3.cmbKodna.AddItem("122")
         .column3.cmbKodna.AddItem("407")
         .column3.cmbKodna.AddItem("505")
         .column3.cmbKodna.AddItem("707")
         .column3.cmbKodna.AddItem("747")
         .column3.Sparse = .F.
         .column3.cmbKodna.style=2 && dropdown listbox
         .column3.cmbKodna.Visible= .T.
         .column3.cmbKodna.boundto=.f.   &&instead .f.
         .column3.cmbKodna.Requery()
         .Visible = .t.
     ENDWITH

***** AND THIS
    thisform.BindControls = .t.
*******************************
ENDPROC 

PROCEDURE KeyPress(nKey, nShift)

    IF nKey == 27
       thisform.Release()
    ENDIF

ENDDEFINE

Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
Hi Borislav,
Your example is great, thanks, just it didn't solve my problem. After starting form with grid and programmaticaly designed combo inside column3 all was fine just first row of Grid always loosed its value in Combo. I solved it using famous Text1 object from Column3, where its value is added at start to Combo as value.
Thanks again for your gain to help.

There is no good nor evil, just decisions and consequences.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top