WinForms - 自定义 XML 编辑器

发布于 2024-08-06 02:43:19 字数 666 浏览 2 评论 0原文

我创建了一个基于 HTML/JavaScript 的小型迷你 Web 应用程序,用于从 XML 文件读取数据。

现在,我需要为此 XML 文件创建一个离线 WinForms 编辑器。我完全意识到使用 XML 文件以我所做的方式存储数据远非理想,但要求是我只能使用网站的静态文件,尽管 XML 文件可以在它被替换时被替换。已更新。

该迷你网络应用程序允许购买远程汽车启动器的客户选择车辆的品牌、型号和年份,并显示安装所需的附加组件列表。该数据在 XML 中表示为 元素,其属性表示制造商、型号、年份以及每种类型组件的属性。

编辑器的要求是:

  • 在网格中显示车辆记录
  • 允许根据已输入的值在每列中自动完成
  • 允许基于列的任意组合进行行过滤

我尝试过以下操作:

  • 使用 DataGridView 和数据绑定,但使用数据绑定/数据集/等似乎不想轻松地使用 XML 文件作为数据源。在与这个问题斗争了几个小时后,我放弃了
  • 创建我自己的自定义“行”控件并将每个元素的实例插入到面板控件中。由于有数百条车辆记录,因此出于性能原因这是不可能的。

我通常是一个网络专家,所以 WinForms 的东西对我来说是未知的领域。满足此编辑器的要求的最简单方法是什么?

I've created a small HTML/JavaScript based mini-web app that reads data from an XML file.

Now, I need to create an offline WinForms editor for this XML file. I'm fully aware that using an XML file to store data in the fashion that I do is far from ideal, but the requirements are such that I can only use static files for the web site, though the XML file can be replaced when it is updated.

The mini-web app allows a customer that is buying a remote car starter to select the make, model and year of their vehicle and be shown a list of additional components that are required for the installation. This data is represented in XML as a <vehicle> element with attributes representing the make, model, year, as well as attributes for each of the types of components.

The requirements for the editor are:

  • Display vehicle records in a grid
  • Allow autocomplete in each column based on values already entered
  • Allow row filtering based on any combination of columns

I've tried the following:

  • Using DataGridView and databinding, but databinding/datasets/etc don't seem to want to play nice easily with XML files as the data source. I gave up after wrestling with this for several hours
  • Creating my own custom "row" control and inserting an instance for each element into a Panel control. Since there are several hundred vehicle records, this is a non-starter for performance reasons.

I'm generally a web guy, so this WinForms stuff is uncharted territory for me. What is the easiest way to accomplish the requirements for this editor?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

拥抱我好吗 2024-08-13 02:43:19

我认为最明智的方法是将用于直观地表示元素的逻辑封装为负责将其数据渲染到单个图形表面上的类,而不是创建一个包含大量较小的 UserControl 来表示每个元素的 UserControl(而不是将逻辑封装在 UserControls 中)。

由于您已经创建了一个“行”控件(我认为具有编辑功能),因此您仍然可以通过创建它的实例并在用户单击它时将其“浮动”在您的控件上来使用它。

这是对有点类似问题的早期回答:

需要帮助创建控件显示数据

展示了基本原理。您可以使用这种方法来编辑非常大的 XML 文档,并且每次只实例化两个控件。

Rather than creating a UserControl that incorporates a large number of smaller UserControls for representing each element, I think the sanest approach is to encapsulate the logic for visually representing the elements as classes that are responsible for rendering their data onto a single graphics surface (as opposed to encapsulating the logic in UserControls).

Since you've already created a "row" control (with editing capabilities, I presume), you can still make use of this by creating an instance of it and "floating" it over your control when the user clicks on it.

This earlier answer to a somewhat similar question:

Need help creating control to display data

shows the basic principle. You could use this approach to edit extremely large XML documents with only two controls being instantiated at any one time.

围归者 2024-08-13 02:43:19

您可以考虑将 XML 文件读入内存并基于该 XML 文件创建类型化数据集。如果您可以控制 XML 文件的格式,则可以从类型化数据集开始,将其序列化为 XML 以获取结构模板,然后从那时起以其他方式工作...编辑 XML 文件并通过以下方式加载数据集从 XML 文件反序列化。

本文讨论了类型化数据集和 DataGridView,还提供了有关如何过滤输入的精彩示例。

最后,您可能想看看免费的 Krypton Toolkit 。它们的控件通常比它们所替代的同等开箱即用的 Winforms 控件更强大。我相信他们可能已经为 DataGridView 实现了自动完成(他们肯定为 TextBox 实现了自动完成)。如果您使用它,您实际上将下载他们的免费工具包和商业工具。确保您只引用工具包 DLL,除非您打算购买其完整产品。

You could consider reading the XML file into memory and creating a typed dataset based on that XML file. If you have control over the format of the XML file, you could start with a typed dataset, serialize it to XML to get a structural template, then work the other way from then on... edit the XML file and load your dataset by deserializing from the XML file.

This article discusses typed datasets and DataGridView, and also provides great examples of how to filter input.

Finally, you may want to have a look at the free Krypton Toolkit. Their controls are generally more powerful than the equivalent out-of-the-box Winforms ones they replace. I believe they may have auto complete implemented for DataGridView (they do for TextBox for sure). If you use it, you will actually download both their free toolkit and their commercial tools. Make sure you only reference the toolkit DLL unless you intend to purchase their full offering.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文