C# - 数据表 - 列属于类型控制 - 导出到 XML

发布于 2024-12-11 19:07:55 字数 597 浏览 3 评论 0原文

问题:当 DataTable 具有 Control 类型的列时,是否有办法将 DataTable 导出为 XML。我收到一条错误,指出控件无法序列化。我已经从各种来源阅读了序列化和数据联系人的整个概念,但我仍然认为手头可能有一个我正在寻找的更简单的解决方案。

背景故事: 我正在创建一个 C# 应用程序,应用程序的控件在不同视图之间循环使用(即,当您加载一个“视图”时,应用程序使用相同的对象,这些对象然后执行不同的任务,例如名为的按钮对象“abutton”可用于在一个视图中提交表单,但在另一视图中时可用于保存文档)。为了使事情变得更加复杂,控件一旦使用就会被禁用,但仅限于该特定的“视图”内,以阻止我两次做同样的事情。我为每个视图创建的数据表会跟踪控件以及它们是否启用。选择视图后,应用程序将加载该视图,然后使用该视图的数据表来确定哪些控件已被禁用。每个视图的数据表具有以下列: ObjectName - 对象的名称 Control - 这是 Control 类型,实际对象存储在该列中 Enabled - 反映对象是否启用的布尔值,默认值为 true

拥有控件类型列并将对象保存到其中,可以在遍历数据表以启用/禁用该特定视图的控件时变得更加容易,我知道我可以取出控制列并解决它,但如果有一种简单的方法来导出 XML 文件,我真的不想这样做。

QUESTION: Is there a way to export a DataTable to XML when the DataTable has a Column of type Control. I get an error stating that the controls cannot be serialized. I have read up on the whole concept of serialized and DataContacts from various sources but I am still thinking there may be a much easier solution at hand that I am over looking.

BACKSTORY:
I have a C# application that I am creating, the controls of the application are recycled between different views(i.e. When you load one "view" the application uses the same objects those objects then carry out different tasks, like for instances a button object named 'abutton' may be used to submit a form in one view but when in another view it may be used to save the document). To make this ever more complicated the controls are disabled once used but only within that particular "view" to stop me from doing the same thing twice. The controls and whether they are enabled is kept track of by a DataTable I create for each view. Once the view is selected the application loads the view then uses the DataTable for that view to determine which controls have been disabled. The DataTables for each view have the following Columns:
ObjectName - Name of the Object
Control - This is of Control type and the actual object is stored in this column
Enabled - Boolean value that reflects whether the object is enabled, the default is true

Having the Control Type Column and saving the object to it makes it much easier when traversing through the DataTable to enable/disable the controls for that particular view, I know that I could take out the Control column and work around it but I really do not want to have to do that if there is a simple way to export the XML file.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文