Click here to Skip to main content
16,021,041 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi...

I came to this point of asking in this site AGAIN because I can't find a better solution in web. My problem is I want to save all the checked checkbox in an xml file and retrieve it for printing purposes.. the xml file will only serve as a temporary database of checked checkbox..

Any help will be appreciated...

Good night and God bless people.. =)


Thanks..
Posted
Comments
RaisKazi 31-Aug-11 11:00am    
It's may not be "Good Night" Time, for everyone :).
You are working on Windows or Web based Application?
[no name] 31-Aug-11 11:06am    
Are you asking how to save a check boxes checked state to an XML file
Sergey Alexandrovich Kryukov 31-Aug-11 13:35pm    
Tag it! WPF, Forms, ASP.NET, what?!
--SA

1 solution

Here is what you need to do: you really need a data layer between UI and persistence. Don't load of store UI in XML; load or store your data layer which you can bind to UI. There are many other reasons to have a separate data layer. In your case it would be just one or more pure-data classes/structures.

If you want to link UI and XML directly you will lock yourself in hard-coupled rigid settings for UI, XML presentation and data which you won't be able to change in any backward-compatible manner. Don't even play with the idea of making you UI serializeable or something like that. Don't operate XML manually.

If you problem is simple enough, you can make some "manual" data binding: develop a procedure of populating you UI (check boxes set or whatever) from the instance of data and make your UI events modifying an instance of data (for check boxes, use the event CheckedChanged; for WPF: Checked, Unchecked).

(Again, stop giving us hard time! I'm tired of checking APIs for three different libraries! Please, always tag your UI library if you use one.)

Now, what to use for persistence? No doubt, use Data Contract. See http://msdn.microsoft.com/en-us/library/ms733127.aspx[^].

There is no need to use XML manually. Data contract automatically provides a non-intrusive way to store and restore any object graph with practically any data. You only add attributed to your types and their members you need to persist; so your programming is purely declarative here.

Please also see my past answers where I advocate this approach:
How can I utilize XML File streamwriter and reader in my form application?[^],
Creating a property files...[^].

I suggest you learn and analyze applicability of the following architectural patterns (http://en.wikipedia.org/wiki/Architectural_pattern_(computer_science)[^]):

MVVM — Model View View Model,
http://en.wikipedia.org/wiki/Model_View_ViewModel[^],

MVC — Model-View-Controller,
http://en.wikipedia.org/wiki/Model-view-controller[^]),

MVA — Model-View-Adapter,
http://en.wikipedia.org/wiki/Model–view–adapter[^],

MVP — Model-View-Presenter,
http://en.wikipedia.org/wiki/Model-view-presenter[^].
Pay attention for the motivation of those architectures. If you understand it, you would be able to create better design ideas.

If you face any problems, ask a follow-up question; I'll gladly answer.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900