c# - Undo redo in window form and gridcontrol -
i have window form has multiple control , grid-view control , want add undo redo functionality form 20 levels,please help.
dtstates = new datatable(); datacolumn dcindex = new datacolumn("id", typeof(int)); dcindex.autoincrement = true; dcindex.autoincrementseed = 1; dcindex.autoincrementstep = 1; dtstates.columns.add(dcindex); dtstates.columns.add("control", typeof(object)); dtstates.columns.add("type", typeof(object)); dtstates.columns.add("value", typeof(string)); dtstates.columns.add("controlid", typeof(string));
this datatable record action of form.but in case of gridview ,i confuse how record , maintain changes.
your gridview show data datatable or better list. need save data. in fact datasource. save objects need deep copy (how do deep copy of object in .net (c# specifically)?) of it. need list hold different versions. if using memento design-pattern , generics can build general class undo/redo can use in other programs or components too.
maybe example can help:
[serializable()] public class clsschnappschuss<t> { private memorystream mvarbeitspeicherzugriff; private binaryformatter mvformatierer; public clsschnappschuss() { if (attribute.getcustomattribute(typeof(t), typeof(serializableattribute)) == null) { trace.writeline(string.concat(typeof(t).fullname, " ist nicht serialisiebar!")); throw new invalidoperationexception(string.concat(string.format("{0} ist nicht serialisierbar.", typeof(t).fullname), " die klasse muss das attribut ", "serializable einbinden ", "[serializable()] ", "um clsschnappschuss verwenden zu ", "können.")); } mvformatierer = new binaryformatter(); } public clsschnappschuss<t> bxspeichern(t obj) { mvarbeitspeicherzugriff = new memorystream(); mvformatierer.serialize(mvarbeitspeicherzugriff, obj); return this; } public t bxwiederherstellen() { mvarbeitspeicherzugriff.seek(0, seekorigin.begin); mvformatierer.binder = new clscustombinder(); t obj = (t)mvformatierer.deserialize(mvarbeitspeicherzugriff); mvarbeitspeicherzugriff.close(); return obj; } }
in class data stored:
public class clsaufbewahrer<t> { private list<clsschnappschuss<t>> liste; public clsaufbewahrer() { liste = new list<clsschnappschuss<t>>(10); } public clsaufbewahrer(int listenkapazität) { liste = new list<clsschnappschuss<t>>(listenkapazität); } public list<clsschnappschuss<t>> schnappschuesse { get; set; } }
Comments
Post a Comment