Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

select row datagrid and display in another datagrid

Status
Not open for further replies.

iara84

Systems Engineer
Oct 25, 2022
13
CO
when i select the first row it doesn't show only the data of the first row, it shows all the data of the table in the second datagrid

main screen

grid1_mtj6bu.jpg


update screen edit first row
grid2_kxhwks.jpg


Add the following property to the form in the Init

ADDPROPERTY(Thisform,"returnobj", null )
in the edit button add the code

SELECT (thisform.Grid2.RecordSource) && selects the cursor area of ​​the grid control.
Thisform.ReturnObj = Newobject("Empty")
SCATTER NAME thisform.ReturnObj
Thisform.Release()
In the UNLOAD event of the grid form

RETURN Thisform.ReturnedObj
when only selecting the second row when editing if the data of the second row appears in the second data grid

update screen edit second row

grid3_jxdtl3.jpg


add this code to position the cursor in the first row of the datagrid, when selecting only the first row it appears in the second datagrid but it does not work. Create the property movefirstgrid and its default value will be .F in the form add to the click event

thisform.movefirstgrid=.T.
thisform.grdprices.setfocus
in the grid add to the setfocus event

if thisform.movefirstgrid
this.activatecell(1,1)
endif

thisform.movefirstgrid=.F.
in the second datagrid only the data of the first row is not show, shows all the data that the table has
 
What is your question, or is that meant as a tip? Tek Tips posting asks for a thread type first. Please pick the lightbulb icon (helpful tip),,, if you don't want to ask a question, which is the default thread type, or pick news or review.

All I can say to what you describe is that a record object surely is one way to get a single record into an object, but on the other side a grid does not have a recordsourcetype that is for a record object, in fact a grid is a multiple records displaying control by nature of it and no matter what record number you point to, a grid shows the table, the active record will be highlighted and will be in the visible lines the grid displays, but neither a SEEK nor a SCATTER NAME will cause a grid to only display that one record, neither the first nor a second grid. To limit a grid to only show one record your options are mainly: 1. Select only one record into a separate result Cursor
2. Set FILTER so only the one record you want to show in the grid is fulfilling that filter, for example SET FILTER TO id=idof the found record or SET FILTER TO RECNO()= some record number. obviously SET FILTER TO RECNO()=RECNO() won't work, so you have to store RECNO() into a variable and then can SET FILTER TO RECNO()=variable, for example. It's easy to see why, imagine the filter is tested for every record, not just the current record, so while RECNO() is the number of the current record SET FILTER TO RECNO()=RECNO() will (virtually) visit all records and check the condition for it, which always is .t., not only for one record. The only way to only filter for one RECNO() is to first tore it into a variable as that variable will not change while all records are visited, whereas RECNO() does change when scanning all records.

Just for sake of completeness a FILTER will not actually cause visiting all records, in fact after you SET FILTER directly you also have to issue LOCATE so the filter causes the workarea to place its record pointer on the first record fulfilling the filter criterion. It will be the first record, if your condition is RECNO()=RECNO(), of course, because 1=1. It is the grid control, specifically, which will continues to display further rows and siplay them until the grid is full, but the grid only does so for it's display, it does not change the current record. Still SET FILTER TO RECNO()=RECNO() will effectively be like no filter at all for any purposes, be it SCAN, LOCATE, CONTINUE, BROWSE or showing the workarea in a grid.

Sorry if I hammer on the RECNO()=RECNO() condition, I am aware you didn't mention it, I don't assume you did this, it was just to illustrate the working of a filter and grid in conjunction.

Perhaps a simpler description of what the grid does is have a secondary look on the workaera you make the grid recordsource to fill the visible rows portion of the grid, without affecting the record pinter in the workare itself. But respecting the SET FILTER condition which actually is bound to only the original workarea. I don't know the behind the scenes implementation of the grid in C++, but it's easy to see that both BROWSE and the grid show more than one record, while still having the active row concept, both browse and grid have the active record indicator, unless you set grid.recordmark=.f., but that only hides that mark, the workarea nd grid still have the active row, addressing alias.fieldname gives you the value of that current rows field, because obviously there is no schrödinger field that is a superposition of the values of all records.

Taken it from the other side, granted you have a record object you create by SCATTER NAME, the grid is not the control to display this record object, there is no mode of a grid or other list based controls like combobox or listbox to display a record object, what you can do is add multiple single textboxes as cells and set their controlsources to each individual recordobjectnmae.fieldname property. In other words you 8use variable based data binding as controlsource. But this kind of binding is only available in controls are single value oriented, like textbox, editbox, checkbos (only special boolean types, though), or spinner ( for numeric fields only). There is no control that displays all properties of an object and displays all object properties. The listbox has a very specific rowsourcetype for arrays and collections, the latter being the VFP "collection" base class or subclasses you make, but a scatter object is neither an array nor a collection. All in all, there are some more very strange and also rarely used rowsourcetypes or recordsourcetypes, but blame me if there is one for single objects I overlook, you mainly use controls for either single fields or lists of records not for this in between thing of a single record with multiple properties that were created from the fields of the source workarea scattered.

Chriss
 
TLDR;

To show only one record in a grid, the easiest option is to do a SQL query INTO CURSOR and thus create a new workarea. That should only have that one record.
The other solution, a SET FILTER, will take effect on the workarea without creating a new one, but would thereby of course effect both the original and second grid.

You can't have two grid fed by the same workarea and let one show all rows and the second only one row.

Chriss
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top