Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Extra rows in grid because of 1 to many relationship
Message
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00055512
Message ID:
00055828
Views:
37
>>>>>>>Gary, try a parameterized grid for your child1 and child2 records instead of letting the grid handle relationships. That way you can put any data you want in.
>>>>>>>
>>>>>>>The asterisks are the same as you will see if you do a Browse with 'set skip on'.
>>>>>>>
>>>>>>>HTH
>>>>>>>Barbara
>>>>>>
>>>>>>That sounds great Barbara. What's a
>>>>>>parameterized grid?
>>>>>>
>>>>>>thanks Gary
>>>>>
>>>>>ARGHH!! I meant a parameterized VIEW!
>>>>>
>>>>>Sorry,
>>>>>Barbara
>>>>
>>>>I hate to sound so stupid but when I click on
>>>>the first parent table what code would be there
>>>>to make this happen. Could you give me an example?
>>>>
>>>>thanks
>>>>Gary
>>>
>>>First you create a view:
>>> Create SQL View as Select field list from table1, table2 where ;
>>> table1.keyfield = table2.keyfield and .... order by ... ;
>>> into cursor CursorName
>>>
>>>
>>>You then use the resulting cursor as the data source for the grid.
>>
>>Mark gave you the code for a regular view. A parameterized view simply adds one more clause in the WHERE section which can be updated programmatically
>>
>> Create SQL View as Select field list from table1, table2 where ;
>> table1.keyfield = table2.keyfield;
>> >>> AND table2.SortField = ?MyVar; <<<<
>> and .... order by ... ;
>> into cursor CursorName
>>>
>>
>>Then be sure you have MyVar programmatically assigned the child value you want to see. You can re-assign MyVar and requery the view whenever Child1/Child2 change.
>
>
>Thanks I guess I'll try this. Maybe you could answer a question
>for me then. In all seriousness. Isn't it easieer to use the
>original way of having a 1 to many relationship set? Assuming
>it worked of course. Why should one have to do all of this in
>order for a simple relationship to work. Would you consider this
>a bug in VFP?
>
>thanks again
>Gary

I didn't follow everything in this thread, but as I understand it, you've got three tables related, and two are in one grid. Grids are designed to handle one cursor at a time. Barbara explained to me in my thread how to use a parameterized view to fill a grid in my many-to-many form. I think that grids would be more complicated and quirky than they already are if they were made more flexible.

In my many-to-many forms, I have table3 as a child of table1 and table2. My form would have text boxes for the fields of table1, and a grid with fields of table2 and one or more fields from table3. The fields of tables 2 and three are in a view with a join condition on table2.key = table3.table2key and table3.table1key = ?table1.key. Table1.key is a parameter of the view, written just like that, so I don't need to assign the parameter a value in code anywhere. I requery this view in my own refresh method.

I also have a form with a relationship somewhat like yours, I think. Table1 is a parent of Table2, and table2 is a parent of Table3. The form has table1 fields in boxes, table2 in a grid, and table3 in another grid. Table2 is also a child of table4, relating table1 and table4 many-to-many. At the moment, table2 has duplicate fields from table4, so that I could use table2 by itself instead of making another parameterized view with table4. This is improper practice, but was an acceptable kludge at the time (I'm about to fix that). The relations make the second grid show the table3 records that are children of the currently selected record in table2. Code was written with the help of Mr. Anonymous Bureaucrat and others to make the selected record in table2 highlighted in its grid even when the grid does not have focus. I can dig up this code if you like.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform