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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

edit and delete multiple textbox

Status
Not open for further replies.

iara84

Systems Engineer
Oct 25, 2022
13
CO
It is possible that by means of the update and delete button it only affects one text box row. When a record is deleted, only the row where the button is located is affected?

edit_and_delete_limx4a.jpg


For example, when the edit button of the first row is clicked, the information of this row is loaded in a second screen to edit it.

actualizar_zei2d5.jpg


this code worked for me with a data grid
SET DELETED ON

IF Messagebox( "Are you sure?", 4 ) = 6
SELECT customers4
DELETE
ThisForm.grid2.Refresh
ENDIF

What should I change for the delete button to work with textbox?
 
Why do you do such things without a grid? In a grid you can have multiple rows and have the same column structure for every row, also buttons are possible.

Taken that aside, you know you need 4 workareas to have 4 separate rows to show in the first form. The second form could be set to form.datasession = 1 to stay in the same datasession as the caller uses and then change its textbox controlsources to the one workarea you want to edit. But ach edit button has to know which workarea it is meant for. And this isn't as trivial as simply working on the active row, when you put all this into a grid.

In short, what you plan to do is no good idea and is not worth continuing, make use of the following:

Instead of your 4 row form with 16 textboes, design a container class that has the 4 textboxes and the two buttons, make that container the currentcontrol of a grid with just 1 column, and the grid will repeat your container. All actions the user does in one container automatically activate the one row it's determined to maintain. The grid column1.controlsource could be th ID off the record, not displayed in any control, doesn't matter. You make sue of the controlsources of the textboxes of your container class. Though you have no grid columns for multiple fields, the grid will take care of the rows and your controls take care of which field to bind to.

If you need help with this, ask in detail. To change controls in the grid was explained in a recent thread, for example: thread184-1818874

Chriss
 
I don't know where you got our idea from, whether you already programmed in legacy Foxpro versions like 2.x, where it was still very common to SCATTER fields and later GATHER them. That seemed elegant as you even have a simple way of cancelling by not GATHERING back the changes.

Today your textbox controlsource can't just bind to variables, you can bid to table.field and you do that. And to still have the control about cancelling or saving you use buffering. Read about that topic in the help.

Let's look in detail about options you also have with your 16 individual textbox controls solution: To still make use of the advantage to bind to workare.field with controlsources of the textboxes, you need one workarea for each record, otherwise you display one record 4 times. You could also choose to scatter into 4 objects, each having the 4 fields as properties or you even scatter into 16 variables. But all that will just mean much too much work to just do what the grid can do with one set of controls for a row and with one workarea, that automatically is set to the row you click on. No matter if you use the individual cells and multiple grid columns, as is the default, or whether you condense it to a single grid column, but put a container with whatever control structure in it you want to use.

I'd also recommend to not introduce an edit mode, you can introduce a system of access rights which tells you whether users should be able to edit ot only read or not even know about a table, but don't make this system of edit/cancel/save within the form, even less so per group of controls for each record. You're not helping the user even on the topic of data integrity, there's enough you can do by having an all form save or cancel option.

Chriss
 
You can also easily implement a list and one set of textboxes for editing in one form. Make this grid readonly and let it just be the control for list overview of data for selecting one active row.
The individual textboxes outside of the grid are then used for editing the grid activated record. And there can of course be more textboxes outside of the grid with many more detail fields you don't need for finding or picking a row, so you can reduce the list to the columns that are most descriptive and selective for the user to pick a record and the textboxes outside of the grid can show all columns of the table.

That way the controlsource of gridworkarea.field suffices, you don't need a controlsource that binds to a field AND a row of a table, you do what controls do by default, bind to the active row.

The formdesigner even makes this kind of design extremely simple. Start a new form design,
Right click and choose Data Environment. Add the table you want to edit to the data environment. Close the "Add Table or View" dialog when you have the tables you need (using the Close button on the right about middle).
Drag the table you want to have in a grid from the data environment into the empty form canvas, drag using the title bar of the table object in the Data Environment.
Drag an individual field of the same table in the DataEnvironment onto a still empty part of the canvas of the form and you get a label plus textbox for that field only.

Now just one line of code: In the Grid1AfterRowColChange put:
Code:
LPARAMETERS nColIndex
Thisform.Refresh()

Now you have a form with a list (in the grid) to pick from and individual controls per field to edit them.
At best, make the grid readonly to the user by setting thisform.grid1.ReadOnly=.T.

Now you can add a delete button with code DELETE in the click event to delete the current row. You would then also set Thisform.Grid1.DeleteMark=.F. as you have your delete button now, which I agree is a better user interface than the delete mark that's black for deleted rows. Nobody intuitively understands that.

But edit mode? For individual rows? Why, who would want such a user interface? Anyway, now you can use the setAll() of all textboxes, that always cover the active record. the grid is readonly anway.

Chriss
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top