insert a new line of row into grid without recordsource

3k views Asked by At

I've some problem to insert a new row line into record without insert into cursor and then append into recordsource. That said i've five record already in existing grid list but i need to add a new line into next row under grid list.

Here is my code:

vc_tmpfile = alltrim(sys(3)) + ".dbf"

create table &vc_tmpfile (text c(254))

append from C:\tmp\aaa.out type sdf

dele all for len(ALLTRIM(text)) < 15

pack

with thisform.grid_list

  Do while !EOF()


     if alltrim(substr(text,1,4)) == "POPL"

         .columns(2).text1.value = alltrim(substr(text,6,6))--->>It shows nothing after insert

     endif

   skip
  enddo

endwith

Appreciate thankful to someone could help.

3

There are 3 answers

0
Stefan Wuebbe On

The VFP Grid control displays data from its RecordSource, and that one is always an "alias".

So the easy VFP way is simply to do an SQL Insert Into yourAlias ..., or use the xBase Append and Replace ... commands.

In your scenario, the Grid.RecordSource probably is the temp table you created, where your code would get improved if you'd use the Create Cursor ... command for creating the temporary table, and by avoiding the infamous & operator and using (name) expressions instead wherever you can

0
JustAspMe On

How did the existing 5 records get into the grid with no recordsource?

You should be updating a record source instead of updating the grid controls...

Maybe take this approach...

1) Stick data into array or temp readwrite cursor

2) Set grid recordsource to the array or cursor

3) Refresh Grid

0
Cetin Basoz On

Looks like this is what you are trying to do:

thisform.grid_list.RecordSource = ''
vc_tmpfile = Sys(2015)
Create cursor (m.vc_tmpfile) (text c(254))
append from ('C:\tmp\aaa.out') type sdf for len(ALLTRIM(text)) >= 15
Update (m.vc_tmpFile) set text = alltrim(substr(text,6,6)) where text like "POPL%"
locate
thisform.grid_list.RecordSource = m.vc_tmpfile