Solved

In Grid editing nightmare

Posted on 2011-09-07
9
314 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 41

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 41

Expert Comment

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

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

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
 
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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 41

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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…
Hyena v12.2 is now available for downloading and is available in English, French, German and Spanish versions.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now