Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Don Higgins
  Where is Don Higgins?
 Peoria
 Illinois - United States
 Don Higgins
 To: Kevin
  Where is Kevin?
 edwardsville
 Illinois - United States
 Kevin
 Tags
Subject: RE: list box combo
Thread ID: 155060 Message ID: 155064 # Views: 1 # Ratings: 0
Version: Visual FoxPro 9 Category: Forms
Date: Sunday, December 23, 2007 7:48:01 PM         
   


Your Original question had nothing to do with a grid. Try to put all information in your questions.

Your grid code should be set up as a Safe Select, this is the only solid error free way to change data in a grid IMHO.

I don't see anywhere in your code the value of your combobox. You assume that the model.index is correct but have you verified this?

My opinion is your select statement should include the Combo.Value instead of model.index.

Here is what I would do to make sure your grid is controlled properly. See http://www.tightlinecomputers.com and see their article on Safe Select for grids.

On my grids I use this procedure, and it works without fail for me.

1) Create form Methods to contain all the code that will update the grid from Anywhere. Code in Methods not events. I call my form method Grid_Refresh for example.

2) Create form PROPERTIES to be the CONTROL SOURCE for each Combo you have that needs to affect the grid's records.
Each Combobox should have a separate form property that is it's control source. The reason I do this is for debugging purposes, but you can use the combo's value instead if you wish.

3) Call this Method from any combo, or command button or textbox (actually anytime there is a value lookup or change).

4) Use the Safe Select example.

Here is My Code, use what you want or need.
* Remember my Grid's Record Source is called csricard. I do not disable it ever, or change to "".

a) in my Valid - or - interactive change of Any ComboBox on my form ( there are 4 available ) I put this code:

ThisForm.Grid_Refresh()


Notice the same form method is fired from each control.

b) Here is my Form Method called Grid_Refresh()
********************************************************************
LOCAL lcwhere, locolumn, locontrol, lltimerenabled, ;
	lcSort_Field, lcSort_Order, lcSort_Join



***********************************************************************
*** Changed By.: Don Higgins on 23 May 2005
*** Reason.....: build the where clause by anding together all the filter conditions
***********************************************************************

* Each Thisform.c name is a form property that is also the control source for my combos
*

lcwhere = []

* Date Combo Box
IF NOT EMPTY( THISFORM.ctimestamp )
	lcwhere = lcwhere + IIF( NOT EMPTY( lcwhere ), [ AND ], [] ) + ;
		[TTOD( TIMESTAMP ) = {] + THISFORM.ctimestamp  + [}]
ENDIF

* Session Combo Box
IF NOT EMPTY( THISFORM.csession )
	lcwhere = lcwhere + IIF( NOT EMPTY( lcwhere ), [ AND ], [] ) + ;
		[SESSION = '] + ALLTRIM(Thisform.cSession) + [']
ENDIF

* Race Car Class Combo Box
IF NOT EMPTY( THISFORM.ccarclass )
	lcwhere = lcwhere + IIF( NOT EMPTY( lcwhere ), [ AND ], [] ) + ;
		[carclass == '] + ALLTRIM(Thisform.cCarClass) + [']
ENDIF

* Car Index Number Text Box
IF NOT EMPTY( THISFORM.ccarnumber )
	lcwhere = lcwhere + IIF( NOT EMPTY( lcwhere ), [ AND ], [] ) + ;
		[carnumber == '] + ALLTRIM(Thisform.cCarNumber) + [']
ENDIF

* Driver's Name Combo Box
IF NOT EMPTY( THISFORM.cdrivername )
	lcwhere = lcwhere + IIF( NOT EMPTY( lcwhere ), [ AND ], [] ) + ;
		[drivername = '] + ALLTRIM(Thisform.cDriverName) + [']
ENDIF

* Winners CheckBox
IF THISFORM.lwinnersonly
	lcwhere = lcwhere + IIF( NOT EMPTY( lcwhere ), [ AND ], [] ) + ;
		[iwin = '] + IIF(Thisform.lwinnersonly,"W","") + [']
ENDIF

IF THISFORM.AllWinnersLosers
	thisform.lwinnersonly = .f.
	thisform.winnersandruns = .f.
	lcwhere = lcwhere + IIF( NOT EMPTY( lcwhere ), [ AND ], [] ) + ;
		[iwin = '] + IIF(Thisform.lwinnersonly,"W","") + [']
ENDIF

***********
*
* Now Create the Select Statement based on the lcWhere local Variable above
*
***********
IF NOT EMPTY( lcwhere )
	SELECT TIMESTAMP, SESSION, carclass, carnumber, drivername,;
		ilane, idialin, ireaction, i60foot, i330foot, ;
		i660foot, i660mph, i1000foot, iquarter, i1320mph, ;
		ioverunder, imargin, iwin ;
		FROM icard WHERE ;
		&lcwhere ;
		ORDER BY &lcSort_Join, TIMESTAMP DESC, SESSION, carclass, carnumber, drivername,;
		ilane, idialin, ireaction, i60foot, i330foot, ;
		i660foot, i660mph, i1000foot, iquarter, i1320mph, ;
		ioverunder, imargin, iwin ;
		INTO CURSOR csrtempicard nofilter

***********
*
* Here is the SAFE SELECT  for use with Grids Section
*
* If the _tally is greater than zero we will REPOPULATE THE GRID with this info
* ONLY after we ZAP the Grid's record source and replace it with the cursor created above
* called csrTempIcard
*
* Note: you cannot RIP the record source out from underneath a grid and have it work 
* reliably
*
***********

IF _TALLY > 0
	*** zap the current Grid records so we can fill
	*** them with the cursor created in the above select statement
	SELECT csricard
	ZAP
	* add records from above cursor
	APPEND FROM DBF('CsrTempIcard')

	* close the temporary cursor, it is not needed any more
	USE IN csrtempicard

	* go to the top record in the grid 
	* Change this if you want a preselected row
	GO TOP IN csricard

	* refresh the form
	THIS.REFRESH()

Endif

* No lcWhere Clause then Get Out now
else
	return
endif





In your case I would build the lcWhere based on the value of the combo box so your code might read
lcWhere = thisform.Cbo_my_Model_list.value

I will take some more time to figure out your code later, right now I have to spend some quality time with the family.

Don Higgins




>
>
> I must still be doing something wrong the values are coming from the item that I just left not the one that is selected.
>
> This is what I have in the interactive change method
>
>
thisform.grid1.RecordSource =space(0)
> 
> 
> SELECT Optionsmodel.selected,model.model,;
>   Options.desc,options.group,options.grouporder,options.cost,options.margin,options.installed,;
>   Optionsmodel.model as model_fk, Optionsmodel.option ;
>  FROM ;
>      boatsale!optionsmodel ;
>     INNER JOIN boatsale!model ;
>    ON  Optionsmodel.model = Model.index ;
>     LEFT OUTER JOIN boatsale!options ;
>    ON  Optionsmodel.option = Options.index;
>  WHERE  Optionsmodel.model = findmodel;
>  INTO CURSOR optionsmodelcursor READWRITE
>  
>  thisform.grid1.RecordSource ="optionsmodelcursor"
>  thisform.grid1.Refresh 

>
>
> I have this in my rowsource
>
>
select alltrim(model.model),model.group,model.index  ORDER BY  Model.group,model.model from model  into cursor models

>
>
> control source is findmodel
> it is bound to column 3
>
>
> I just changed to this and it seems to work?
> I thought I could use the bound to?
>
>
thisform.grid1.RecordSource =space(0)
> 
> 
> SELECT Optionsmodel.selected,model.model,;
>   Options.desc,options.group,options.grouporder,options.cost,options.margin,options.installed,;
>   Optionsmodel.model as model_fk, Optionsmodel.option ;
>  FROM ;
>      boatsale!optionsmodel ;
>     INNER JOIN boatsale!model ;
>    ON  Optionsmodel.model = Model.index ;
>     LEFT OUTER JOIN boatsale!options ;
>    ON  Optionsmodel.option = Options.index;
>  WHERE  Optionsmodel.model = models.index;
>  INTO CURSOR optionsmodelcursor READWRITE
>  
>  thisform.grid1.RecordSource ="optionsmodelcursor"
>  thisform.grid1.Refresh 




Don Higgins






ENTIRE THREAD

list box combo Posted by Kevin @ 12/23/2007 5:55:52 PM
RE: list box combo Posted by Don Higgins @ 12/23/2007 6:08:19 PM
RE: list box combo Posted by Kevin @ 12/23/2007 6:18:38 PM
RE: list box combo Posted by Don Higgins @ 12/23/2007 7:48:01 PM
RE: list box combo Posted by Kevin @ 12/23/2007 8:25:30 PM
RE: list box combo Posted by Don Higgins @ 12/23/2007 8:51:31 PM