In Grid editing nightmare

Hi all
i need to use "in grid" editing (something i never do) in the following scenario:
I have table1 where i enter employee schedules: employeeid, time_in, time_out
I also have Table2 with employee names: employeeid, lastname, firstname
Table1 is recordsource for the grid. In column1 i entered table1.employeeid, in column2 controlsource is allt(lastname)+" "+allt(firstname)  -- column2 is readonly, column3 controlsource is time_in and column4 controlsource is time_out.
The problem is that i cannot have the employee name displayed correctly in time . When entering new records, it will not update the name, or it will update the current name for all the others in the column etc...I tried using 2 employees tables - 1 with a relation set for displaying in the grid, and the other one for lookup when needed, still no go...tried playing with the sparse property of the column, but still nothing.
Table1 has buffermode 5.
How can i have it display correctly the names according to employeeid, particularly when adding a new line

Thanks for your help
Jaime

LVL 2
GreatSolutionsC.I.OAsked:
Who is Participating?
 
pcelbaConnect With a Mentor Commented:
Hmm, THIS.Parent... does not work but

(IIF(SEEK(Table1.EmployeeId, "Table2", "employeeid"), allt(Table2.lastname)+" "+allt(Table2.firstname), " "))

works fine.
0
 
pcelbaCommented:
You may try the following column2 ControlSource expression:

(IIF(SEEK(THIS.Parent.column1.value, "Table2"), allt(Table2.lastname)+" "+allt(Table2.firstname), ""))

(I did not try it yet)
0
 
pcelbaCommented:
The value reference should probably be

THIS.Parent.column1.Text1.value
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
Olaf DoschkeSoftware DeveloperCommented:
The last SEEK would also be doable as a relation between table1 and table2:

Set Order To employeeid in Table2
Select Table1
Set Relation To employeeid Into Table2

The code could be in form or grid init, anywhere the two tables are already open. And as Pavels SEEK solution, this needs an index on employeeid in Table2.

Column2.controlsource should be set to (allt(table2.lastname)+" "+allt(table2.firstname))

Including the outer parathesis. As you don't use a differing control you don't need to set column.Sparse=.F., this is just needed in cases you want the grid to draw a currentcontrol into any row, and not just the current row.

Controlsource values are never computed sparsely. if you see repeated value, this is normall just a side effect of a differing control, than the original Text1 Textbox of each grid column. In your case the repeating values simply come from table2 not being the recordsource of the grid, but VFP get's the field content of lastname and firstname from table2, from the same record, over and over again. That's why it's repeated.

As you said you tried a relation, what exactly did you try? It seems not to have worked. Have you perhaps set the relation from table2 to table1 instead?

Bye, Olaf.

0
 
GreatSolutionsC.I.OAuthor Commented:
The simplest solutions are always the greatest!!!
Thanks again
0
 
GreatSolutionsC.I.OAuthor Commented:
Olaf, i did of course set relation from table1 to table2, that's why when viewing the grid all the data was always correct. The problem started when editing the grid and entering an employeeid value. Peter's solutions worked a treat in that case

Jaime
0
 
Olaf DoschkeSoftware DeveloperCommented:
Well, Grid.Refresh() should update. Also a new employeeid only will take effect, once you left the field. Buffering may also lead to delayed reference.

But if it works, it works.

Bye, Olaf.
0
 
pcelbaCommented:
Hmm... This could also mean relations are not working correctly in buffer mode 5.

I cannot explain why relation did not work but SEEK is O.K. It would probably need some more investigations.
0
 
GreatSolutionsC.I.OAuthor Commented:
Exactly, at first i did run Grid.refresh() in the lostfocus() event of employeeid, but still was messy. SEEK worked great, i cannot believe i missed that method after 20 years of suffering :-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.