25-May-15
Log In
Products
Buy
SUPPORT CENTER
Support
Tickets
My Account
Examples
About Us
Localization
FAQ
solution
Training Events
ID:
T210787
Created O n :
2/18/2015 2:12:34 PM
Mo dified O n :
3/11/2015 12:59:36 PM
B u ild:
v2014 vo l 2.3 / 4-Dec-2014
[DevExpress Support Team: CLONED FROM T210099: How to synchronize XPServerCollectionSource with BindingContext?]
Furthermore, i really appreciate your help / advise:
This is my szenario:
Related Questions
old szenario: No server mode, XPcollection, Custom-Editform (not everythings possible with editform), slow
new Szenario: Server Mode, new form for adding/editing, either linked by CurrencManager or (what do you think) by fetching the selected record again
with XPcollection on the new form (no server mode) and refreshing the grid after leaving the input form. Please feel free to comment, i really need your
input
Code:
on Doublecklick show the form: ff.ShowDialog(ID)
search the selected record inside the new form: XpCollection1.CriteriaString = "ID=" & id
Save the record after changes are made : Session1.Save(XpCollection1)
refresh the grid after leaving the form and hold the current row:
[VB.NET]
W h at is th e b est w ay to ch an ge
O b jectClassIn fo fo r xp co llectio n at
ru n time
Sh o w Mo re
Leave a Comment
1 Solution
0
You can simply pass to the edit form persistent object that you want to edit. I have attached a simple example illustrating this approach.
In the edit form I use the XPCollection with the LoadingEnabled property set to false. I do not need to load any objects, I just want to add a single object to
edit its properties. I also do not bind the XPCollection to the Session at design time. I do it at run time using the ResolveSession event. This trick helps me
bind the XPCollection to the Session instance related to the parent Form and avoid mixing different Sessions.
In the edit form constructor, I create the NestedUnitOfWork and use it to reload the object passed from the parent form. The purpose of the
NestedUnitOfWork in this example is to allow users to cancel changes without affecting objects in the parent form. If you want to learn more about nested
unit of work, refer to this article: Nested Units of Work.
When the user clicks the "Save" button in the edit form, I execute the CommitChanges method of the nested unit of work. This method update changed
objects in the parent Session. In other words, a corresponding record in the GridView will be automatically updated. You do not need to call the
XPServerCollectionSource.Reload method or use dirty hacks such as clearing the Session's identity map.
If the XPServerCollectionSource is bound to the Session instance, changes made in the edit form will be automatically saved to the database. If the
XPServerCollectionSource is bound to the UnitOfWork instance, you need to execute the CommitChanges method after the edit form is closed.
To add a new record, create a new persistent object instance and pass it to the edit form as a parameter. This time, however, you will need to reload the
XPServerCollectionSource, because the new object will not automatically appear in the grid. Executing the XPServerCollectionSource.Reload method will be
sufficient. Also, if you want to immediately display the added record to a user, use the GridView.LocateByValue method to obtain the handle of a row that
displays the new object and assign the result to the GridView.FocusedRowHandle property.
Attached is a sample project demonstrating how to implement this.
T210099VB.zip
https://www.devexpress.com/Support/Center/Question/Details/T210787
1/3
T210787 - Editing an XPO object in a separate Form in Server Mode | DevExpress Support Center
25-May-15
O n e remake, th e ro u tin e (FLS_PO STEN w ill also w o rk w ith co n tacts, b u t n o t ch an gin g, ju st readin g)
If i u se
An y ideas ?
[VB.NET]
[VB.NET]
Me.BindingContext(Me.XpCollection1).EndCurrentEdit()
Me.Session.CommitChanges()
Me.Session.BeginNestedUnitOfWork()
Dim cont As CONTACTS = Session.GetObjectByKey(Of CONTACTS)(co.ID)
cont.NOTES0 = "test"
Me.Session.CommitChanges()
Co u ld it b e th at U O W h as p ro b lems th ere (iden tity fields):
[SQL]
DEVEXPRESS
About Us
News
Our Awards
Upcoming Events
User Comments
Case Studies
Reviews and Publications
Licensing
Purchasing
MVP Program
Contact Us
Logos
.NET CONTROLS
WinForms
ASP.NET
MVC
WPF
Silverlight
Windows 8 XAML
CROSS PLATFORM
Reporting
Document Automation
Leave a Comment
MOBILE
DevExtreme Mobile
HTML5 JS WIDGETS
DevExtreme Web
ENTERPRISE TOOLS
Report Server
Analytics Dashboard
iOS 7
DataExplorer
FRAMEWORKS
eXpressApp Framework
CODE-DEBUG-REFACTOR
CodeRush for Visual Studio
SUPPORT
Search the Knowledge Base
My Questions
Code Examples
Getting Started
Demos
Documentation
Blogs
Training
Webinars
Current Version/Build
Version History
FOLLOW US
If you need additional product information, write to us at info@devexpress.com or call us at +1 (818) 844-3383
https://www.devexpress.com/Support/Center/Question/Details/T210787
2/3
T210787 - Editing an XPO object in a separate Form in Server Mode | DevExpress Support Center
25-May-15
https://www.devexpress.com/Support/Center/Question/Details/T210787
3/3