views:

370

answers:

2

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?

A: 

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.

Eric J.
A: 

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:

http://stackoverflow.com/questions/1342689/need-help-creating-control-to-display-data/1342891#1342891

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.

MusiGenesis