Remove Redo actions in Memento? - catel

In my application a user can add rows to a DataGrid and change properties of each row. The user can also delete rows. It works fine to undo and redo these actions but if the user adds rows, say three, modify some values and then undo back to where there is only one row and then add a new row it seems illogical to be able to redo the undos(having new rows appear after the last added one). Thus when the user adds a new row I want to delete all Redos.
I tried to use RedoBatches to get an enumeration of all redos and then do Clear on each to remove them but the Redo button is still active and will Redo these actions when pressed.
Is this the proper way to try to achieve this or is it not possible or should I do it differently?

When adding items using an object, you can use UnregisterObject to unregister. It will automatically remove empty batches as well.
Another hack is to cast the Undo / Redo batches properties to a List<> and modify them accordingly (but note that you are "messing" with internals in that case).

Related

Generate comboboxes depending on number inserted in first combobox

I'm doing an userform where in one of the fields (lets say its combobox1) the user is asked for the number of failures, and for each failure he has to put the type of failure, number of part and in another field the type of rework (3 fields to fill for each failure). And what I would like to know if that if it's possible to generate comboboxes depending on the number of failures made. For example: if the user puts 3 in the field of failures, 9 comboboxes should appear and so on.
I also think that maybe another way would be to have the standards 3 comboboxes and clear the fields each time the user press a button and a counter appears indicating which failure description he is filling, but I would also like to know how this could integrate into the whole userform, which already has a "submit" button.
Maybe there could be another reasoning for this, and I would greatly appreciate any help.
I don't really have much experience using dynamically created tabstrips, but they may be helpful with creating the layout you're describing. I would recommended in the base userform, include a tabstrip with a single tab and the 3 comboboxes/textboxes that are needed for a single failure. (You could keep it invisible until after "combobox1" has a value, if desired) Then use the number from the combobox to dynamically create the additional tabs on the tabstrip:
Private Sub ComboBox_Change()
'To remove previous tabs if combobox changed
For i = 1 To TabStrip1.Tabs.Count - 1
TabStrip1.Tabs.Remove(i)
Next i
'Adding additional tabs to tabstrip
For i = 1 To ComboBox.Value - 1
TabStrip1.Tabs.Add
Next i
End Sub
The tab currently selected can be identified by using the TabStrip1.Value property. I think the change event is queued by the TabStrip1.Value changing.
You will have to manually clear out any values when the tab strip changes (or fill back in values they previously filled out but want to view again).
However, since you'd be determining which tab you're on by "index" (the .value property) you could create a 2d array (redim it to correct rows/columns based off combobox1's value) and use the tab "index" to store combobox values and retrieve existing values for when the user switches back to an existing tab.
And maybe consider "locking" the combobox1 so the value can't be changed by accident. This could be accomplished by having a variable initialized to, maybe -1, which gets set to the combobox value after they've started adding infor to the incidents. Or don't remove any tabstrip tabs, only add if the number is greater than the existing count. (If you want them to put in whatever value they'd like, maybe consider using a textbox?)

How to replace one records with many (ie explode a group into pieces) when entering?

I am trying to figure out the best approach for something - I have added an additional table to the Sales Order screen as a new tab and it works fine to save records into it. The next thing needed is to potentially explode a value into many lines if it is a certain type. So if they enter a "kit" into my grid/tab - we would want to replace the kit with its components and not have the kit in the grid anymore.
I know how to insert the records etc. My biggest concern is which event to do the work under (field or row level and -ed vs -ing) . I know I could potentially create an endless loop if I don't do it properly.
**edit - I tried using RowInserting - I can cancel the inserting and add my records in there - however it does not trigger the screen to refresh from the cache. If i Save the order - it will display my new rows properly. however, i dont want to do a save in my code. I am also concerned about it triggering another rowinserting.
With rowinserted - it seems to be the same with the screen not refreshing and also i get an error about the row that i deleted.
We had a similar request and what we did is instead of adding the item in grid level and waiting for a trigger, we added a grid tool bar button that pops up a small smart panel to select the kit item, its version and the quantity required. Then we inserted the component lines to the grid with required calculations.

Using Relational Controls, how do you do a "soft" delete

In the relational controls sample db (xpagesjdbc.nsf) there is an example called JDBC_RowSetDatasource. This uses a view panel and has the check box turned on in the view panel to allow the user to select a document. Then there is a button to delete the selected docs using a simple action, delete selected documents. This deletes the document but until the button with the code that has jdbcData1.acceptChanges() is pressed the changes are not committed and the row shows as to be deleted (first icon column with the isRowDeleted() call to determine the icon).
I am working on a similar situation but with a repeat control. I can delete the row with #jdbcDelete but that is immediate. Looking at the data it shows the row is gone from the data even before acceptChanges() is called.
Since I can't use the simple action to delete selected documents (no view panel) what is the Java equivalent to delete the row in a similar manner? I have tried deleteRow() on both the variable for the data set and for the row but get an error in both cases.
Howard, the simple action just memorizes the primary keys of the records as to be deleted. If you want to simulate that you need to take a similar approach (using a ViewScope variable or bean) to keep track of your "deleted" records and a method that executes the actual deletion.
Smells like a case for a bean

Specifying which column a button will be placed in

I am using TableLayout, and when I am placing a button, I want to specify which column the button should be placed in. For example, column 4. The dirty way to go around this is to place 3 empty views before I place the button.
But, is there a better way? I was told to use android:layout_column="4" in the code, but it made the application crash.
The solution that I found is by using the view its basically an empty view that just takes up space in the view its placed in. Alternatively a can be used, will be able to do what I wanted to do before BUT unfortunately the columns and rows aren't distributed evenly or automatically which is a drawback.

Excel User Form, Previous Button

I have an excel user form for data entry, at the moment the form functions so that users can add data. I would like to add a previous,next, first and last case button so that users can make edits via the form. The code I used for the form was derived from this website: http://www.contextures.com/xluserform02.html
If someone could describe how to add those command buttons to that form I would be very appreciative!
Thanks!
I have a tutorial on my site that almost does what you want.
http://www.dailydoseofexcel.com/archives/2004/09/09/linking-userforms-and-worksheets-part-v/
It uses a scrollbar instead of buttons, but you may be able to adapt it. The basic steps are
Load the current row data into the form
Store the current row
When a button is pushed, change the stored row (to +1, -1, the first row, or the last row)
Load the new row's data
Then you have to have code that determines if the current record has been changed. If it has, you have to write the changes or give the user the option to write or discard.
Also, you may want to disable the First and Previous buttons if the user is on the first record. Similar for Last and Next and the last row.
The tutorial on my site has all that code and a downloadable workbook that you can follow along with. Good luck.

Resources