Solved

In Grid editing nightmare

Posted on 2011-09-07
9
344 Views
Last Modified: 2012-05-12
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

0
Comment
Question by:GreatSolutions
  • 4
  • 3
  • 2
9 Comments
 
LVL 42

Expert Comment

by:pcelba
ID: 36494775
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
 
LVL 42

Expert Comment

by:pcelba
ID: 36494784
The value reference should probably be

THIS.Parent.column1.Text1.value
0
 
LVL 42

Accepted Solution

by:
pcelba earned 500 total points
ID: 36494893
Hmm, THIS.Parent... does not work but

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

works fine.
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 29

Expert Comment

by:Olaf Doschke
ID: 36496994
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
 
LVL 2

Author Closing Comment

by:GreatSolutions
ID: 36501166
The simplest solutions are always the greatest!!!
Thanks again
0
 
LVL 2

Author Comment

by:GreatSolutions
ID: 36501176
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
 
LVL 29

Expert Comment

by:Olaf Doschke
ID: 36501562
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
 
LVL 42

Expert Comment

by:pcelba
ID: 36501670
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
 
LVL 2

Author Comment

by:GreatSolutions
ID: 36504460
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

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Visual FoxPro (short VFP) is a programming language with it’s own IDE and database, ranking somewhat between Access and VB.NET + SQL Server (Express). Product Description: http://msdn.microsoft.com/en-us/vfoxpro/default.aspx (http://msd…
Many businesses neglect disaster recovery and treat it as an after-thought. I can tell you first hand that data will be lost, hard drives die, servers will be hacked, and careless (or malicious) employees can ruin your data.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question