Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Refreshing Data in a Grid
Message
From
19/08/2004 11:35:06
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00934445
Message ID:
00934540
Views:
21
Neil,
First keep in mind that setting properties in PEM sheet you're limited to 255 chars (but do not trust over 253 in every version - a reason for mismatched push/popjmp call or C..5 error).
OTOH programmatically you can bypass that limit. Where to place code is a good question. You might put the code in init of objects (combo1,2 and grid). But that has a problem, you might not be sure at all times, your SQL for grid is error free as it might depend on another object and it should be initialized first. Well, then, do not code in their init but in form init. It goes like this :
Combo2 needs Combo1 value and Grid1 needs both of them.
*Form.Init
Set Combo1
Set Combo2
Set Grid1
*Form.init
*Previous combo init code
with this.Grid1
  .RecordSource = ""
  .RecordSourceType = 4
  .RecordSource = 'Select distinct * '+;
    '  from neil'
    '  where moc034 = trim(crsProduct.Type) and'+;
    '        moc011 = trim(crsSubProduct.SubType)'+;
    ' into cursor crsresult'
endwith
Here is a sample using Customer table ( assume Country=Type and City=SubType)
-Create a form
-Add customer to DE
-Select company,cust_id,city,country fields and drag on form to create grid
-Add 2 combos
Codes :
*Form.init
With This.Combo1
  .RowSourceType = 3
  .RowSource = 	' select country,Upper(country) as ID where !Empty(country) from customer'+;
    ' union'+;
    ' select "--All--" as country,"" as ID from customer'+;
    ' order by ID'+;
    ' into cursor crsCountry'
  .ListIndex = 1
Endwith
With This.Combo2
  .RowSourceType = 3
  .RowSource = ;
    'select city,Upper(city) as ID from customer where !Empty(city) and '+;
    '    Upper(country) = Trim(crsCountry.ID)'+;
    '  union'+;
    ' select "--All--" as city,"" as ID'+;
    '  from customer'+;
    '  order by ID'+;
    '  into cursor crsCity'
  .ListIndex = 1
Endwith
With This.grdCustomer
  .RecordSourceType = 4
  .RecordSource = 'select cust_id,company,city,country'+;
    ' from customer'+;
    ' where Upper(country) = Trim(crsCountry.ID) and'+;
    '       Upper(city)    = Trim(crsCity.ID)'+;
    ' into cursor crsCustomer'
Endwith

*Combo1.InteractiveChange - note that .RecordSource = .RecordsSource implies refresh
With this.Parent.combo2
	.Requery()
	.ListIndex = 1
EndWith
With this.Parent.grdCustomer
	.Recordsource = .Recordsource
endwith
*Combo2.InteractiveChange - note that .RecordSource = .RecordsSource implies refresh
With this.Parent.grdCustomer
	.Recordsource = .Recordsource
endwith
Note that there is no reference to combo.value or displayvalue. Who cares, we directly get the value from its cursor, any field we want (ie:crsCountry.ID which is a calculated field in cursor and combo columncount is in its default 1). Modify code with your table and fieldnames and you should be OK :)

PS: You might see a working example of this in FoxyClasses samples. Check MoverListXX class sample.
Cetin




>Cetin,
>
>Could you help me please I seem to have got myself in a muddle.
>
>I have a grid on a form. In the property window for the grid I have set the following:
>
>
>recordsource='Select distinct * from neil'+;
' where thisform.combo1.displayvalue=moc034 and thisform.combo2.displayvalue=moc011'+;
' into cursor crsresult'
>
>recordsourcetype=4
>
>
>So basically when I run the form for the first time I should get a list of records.
>
>Problem1 - why can I not see any records. In which event would I put this syntax programmatically rather that use the properties window i.e. init, load event.
>
>Now I have 2 combos, 1 for type and 1 for subtype in which you helped in relating the 2 for which is working. What I would like to do is by using these combos will determine which records will be shown. The problem is that the combos by default are blank and therefore when the grid initialises I think the values for both combo's are Null and therefore no records.
>
>What I would like to do is this:
>
>Load up form and populate the grid with all records from table neil.
>
>I then want the linked combos to manipulate the grid. In addition to this I need some form of option called ALL so that when the user selects this in combo1 I get back to all the records again. I suppose this should be set to All when the form loads.
>
>So what I have is this code in the init event when the form loads:
>
>
>SET EXCLUSIVE OFF
>SET DEFAULT TO ("C:\Foxpro Projects\Statistics")
>
>with thisform.combo1
> .RowSourcetype = 3
> .Rowsource = 'Select distinct type from products order by type into cursor crsproduct'
> .ColumnCount = 1
>ENDWITH
>
>with thisform.combo2
> .RowSourcetype = 3
> .Rowsource = 'Select subtype from products where type=crsproduct.type order by subtype into cursor crssubtype'
> .ColumnCount = 1
>ENDWITH
>
>
>Then I have the syntax above code in the properties window for grid because I do not know which event to put it in.
>
>Plus here is the code for the combo1:
>
>
>*Combo1 interactive change event
>with thisform.Grid1
> .recordsource=.recordsource
> .refresh()
>ENDWITH
>
>With This.Parent.combo2
>      .Requery()
>      .ListIndex=0
>    ENDWITH
>
>
>
>Any pointers would be greatly appreciated. Sorry for the long email!
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Reply
Map
View

Click here to load this message in the networking platform