Re: tables
- From: Peter Duniho <NpOeStPeAdM@xxxxxxxxxxxxxxxx>
- Date: Thu, 20 Sep 2007 12:09:58 -0700
RobcPettit@xxxxxxxxxxx wrote:
[...] In excel Ive got 4 small tables (9x9), which I use
vba to sort the data and allocate to the correct table. [...]
The next stage is to
bypass excel altogether and have the data within the application
itself.
In code, it seems like a single-dimensional array of 4 2-dimensional arrays would be fine. For example, assuming your data is floating point doubles:
double[][,] tables = new double[][,] { new double[9,9], new double[9,9], new double[9,9], new double[9,9] };
There are lots of other ways to store the data as well. Which is truly best depends somewhat on how you actually want to use the data.
I wouldn't use a Datagrid unless there was some specific functionality in the Datagrid that you specifically needed. Just because you were using Excel before, that doesn't mean that the data needs to be in any sort of Excel-like object when it's entirely contained within the application.
As far as saving goes, you have a variety of options, but one of the simplest is to put the data in your applications settings and use the Properties.Settings.Default class to read and write them. That way your code only has to deal with the in-memory representation, and all of the serialization is handled for you.
The array of doubles won't automatically serialize, so probably the best thing to do there is write some custom code that writes to a StringWriter based on a StringBuilder, and then save the resulting string in the application settings. Then you can reverse the process, using a StringReader to parse data from the string retrieved from the application settings.
If you use XML, you can use the XmlWriter and XmlReader classes to format the data as XML when saving and parse the XML when reading it back in.
All of the above can work using StreamWriter and StreamReader with a file instead.
Basically, once you've figured out what format in which you want to store the data, you should be able to store that to a file or to the application settings, however you prefer. You have a small amount of data and there may be some benefit in leaving it human-readable, so IMHO converting the data to text and saving it that way would work well. But there's no requirement that you do it that way if you feel a different format would work better (though, storing it as text does make the application settings method easier).
Pete
.
- Follow-Ups:
- Re: tables
- From: RobcPettit@xxxxxxxxxxx
- Re: tables
- References:
- tables
- From: RobcPettit@xxxxxxxxxxx
- tables
- Prev by Date: Re: Overline in label
- Next by Date: RE: Assembly.Load() and updating DLLs on the fly
- Previous by thread: tables
- Next by thread: Re: tables
- Index(es):
Relevant Pages
|