Which controls do I add to show, edit and save test parameters?

B

BobG

Old console app c programmer here trying to get something done in c#
and windows forms. I have a form with buttons like 'motor on' and
'valve open' text boxes like 'CFM' and 'PSI'. The buttons send one
character commands out the serial port, and the CFMs and PSI comes
back. I thought I was Almost Done when I got this working. I added a
tab called Edit where the user can tweak the numbers in a table with
heading like 'model number' 'cfm' 'psi' 'amps'. I have a half dozen
model numbers with slightly different editable test params. At first I
thought I needed a datagridview, but someone says 'You dont need a
relational database, just a table or flat file'. Any hints on which
control would let me open the file, edit the cells, and save it back?
In the 'old days', I'd whack on it manually, fopen, readln, scanf,
fwrite, fclose. Hopefully there is a control do do some or most of
this nowadays? I guess I'm only about two decades behind the tip of
the wave... Thanks for some gentile suggestions. Never stop learning
in the programming business.
 
Z

Zach

Old console app c programmer here trying to get something done in c#
and windows forms. I have a form with buttons like 'motor on' and
'valve open' text boxes like 'CFM' and 'PSI'. The buttons send one
character commands out the serial port, and the CFMs and PSI comes
back. I thought I was Almost Done when I got this working. I added a
tab called Edit where the user can tweak the numbers in a table with
heading like 'model number' 'cfm' 'psi' 'amps'. I have a half dozen
model numbers with slightly different editable test params. At first I
thought I needed a datagridview, but someone says 'You dont need a
relational database, just a table or flat file'. Any hints on which
control would let me open the file, edit the cells, and save it back?
In the 'old days', I'd whack on it manually, fopen, readln, scanf,
fwrite, fclose. Hopefully there is a control do do some or most of
this nowadays? I guess I'm only about two decades behind the tip of
the wave... Thanks for some gentile suggestions. Never stop learning
in the programming business.

There is no one step singe summary solution to what you want to achieve.
You will have to make a breakdown into logical steps and code each of
them them. A listview could do the trick.
 
Z

Zach

[...]I added a
tab called Edit where the user can tweak the numbers in a table with
heading like 'model number' 'cfm' 'psi' 'amps'. I have a half dozen
model numbers with slightly different editable test params. At first I
thought I needed a datagridview, but someone says 'You dont need a
relational database, just a table or flat file'. Any hints on which
control would let me open the file, edit the cells, and save it back?

There's no one control that will do all that, nor IMHO should there be.
Serialization is a lot different from UI and there's no reason to tie
the two together.

That said, if the presentation you envision is in fact tabular in
nature, I would think that DataGridView would be the obvious choice to use.

Whether you connect the DataGridView to a database, or just enumerate
the rows manually and write to a CSV text file, or something in
between…that shouldn't matter. As far as the UI goes, what's important
is that the UI looks like what you need, and it sounds like you want
something that looks like DataGridView. So that's a good one to use.

Likewise, how the data is stored doesn't depend on the UI. Whether you
use a DataGridView or a bunch of manually placed TextBox controls or
something else, you can save that data however you like.

The easiest way to save data is to use the built-in serialization
support. Two commonly used mechanisms are the BinaryFormatter class and
the XmlSerializer class. There's even a SoapFormatter class if you want
your data to be SOAP-compatible. Just store the data you want to save in
some type (maybe a built-in collection type, or maybe some user-defined
type…depends on the exact nature of the data) and then serialize the
object to a FileStream, StreamWriter, XmlWriter, etc. (as appropriate to
the serialization you're doing).

Pete

I understand that this man is coming from c and is new to C#. How about
a simple random file with record numbers coinciding with the line
numbers of a simple listview?
 
Z

Zach

"Simple random file" is non-descriptive. It could describe practically
any file-based serialization (and of course, taken literally it's not
useful for serialization at all…a file containing random data isn't the
same as a file containing the actual data one wants to keep; but surely
you didn't mean that literally).

As far as the UI goes, whether a ListView works for him or not depends
on what exactly he's looking for. It sounds like he wants the user to be
able to edit the information in a tabular format, for which DataGridView
is more appropriate. ListView also puts restrictions on how you can
organize the columns, in that rather than plain rows, each row in a
ListView has a primary label, followed by "subitems".

It might be worth the OP at least looking at that control as well, but I
suspect that DataGridView is more likely to support the specific kinds
of editing scenarios he seems to be describing.

Pete

Yes Pete ok. My line of thought was that coming to a new language from
C, one needs to learn the basics of reading and writing from and to a
file any way. With the fields of the records of the file matching the
columns of the list, writing the list when changed, using a simple data
entry routine, would do the trick I thought. But yes, this solution
would be less elegant. (And you don't even need to bother with record
numbers as I suggested.)

Zach.
 
Z

Zach

Old console app c programmer here trying to get something done in c#
and windows forms. I have a form with buttons like 'motor on' and
'valve open' text boxes like 'CFM' and 'PSI'. The buttons send one
character commands out the serial port, and the CFMs and PSI comes
back. I thought I was Almost Done when I got this working. I added a
tab called Edit where the user can tweak the numbers in a table with
heading like 'model number' 'cfm' 'psi' 'amps'. I have a half dozen
model numbers with slightly different editable test params. At first I
thought I needed a datagridview, but someone says 'You dont need a
relational database, just a table or flat file'. Any hints on which
control would let me open the file, edit the cells, and save it back?
In the 'old days', I'd whack on it manually, fopen, readln, scanf,
fwrite, fclose. Hopefully there is a control do do some or most of
this nowadays? I guess I'm only about two decades behind the tip of
the wave... Thanks for some gentile suggestions. Never stop learning
in the programming business.

Further to Pete's advice have a look at
http://www.codeproject.com/KB/cs/objserial.aspx
just look at the examples per se
 
Z

Zach

Yes Pete ok. My line of thought was that coming to a new language from
C, one needs to learn the basics of reading and writing from and to a
file any way. [...]

Why? If the environment provides a more convenient, easier-to-learn
technique for persisting data to a file, why do they _need_ to learn
lower-level techniques?

I don't suggest that before one uses FileStream, they learn to use the
unmanaged Win32 API on which FileStream is based. Nor is it likely to be
important that before a person uses the unmanaged Win32 API that they
learn how to communicate directly with file system drivers.

Mainstream programming environments like .NET always involve many layers
of abstraction. It might be useful to the OP one day to learn how to use
FileStream and similar objects to handle file i/o. But if all they need
to do at the moment is save some data to the disk and they have no
external criteria defining the file format, I see no need at that moment
to go any further than the built-in object serialization mechanisms.

Pete
Pete, your point makes good sense.
Zach.
 
A

Arne Vajhøj

Old console app c programmer here trying to get something done in c#
and windows forms. I have a form with buttons like 'motor on' and
'valve open' text boxes like 'CFM' and 'PSI'. The buttons send one
character commands out the serial port, and the CFMs and PSI comes
back. I thought I was Almost Done when I got this working. I added a
tab called Edit where the user can tweak the numbers in a table with
heading like 'model number' 'cfm' 'psi' 'amps'. I have a half dozen
model numbers with slightly different editable test params. At first I
thought I needed a datagridview, but someone says 'You dont need a
relational database, just a table or flat file'. Any hints on which
control would let me open the file, edit the cells, and save it back?
In the 'old days', I'd whack on it manually, fopen, readln, scanf,
fwrite, fclose. Hopefully there is a control do do some or most of
this nowadays? I guess I'm only about two decades behind the tip of
the wave... Thanks for some gentile suggestions. Never stop learning
in the programming business.

There are plenty of possible options:
* database, one row per model
* XML, one file per model
....

I would definitely decouple the UI from the storage.

So you should have a class that represent the data. And
the UI edit an instance of that class and storage save
and load.

Th storage save and load should be easy for both database
and XML.

Arne
 
A

Arne Vajhøj

Mainstream programming environments like .NET always involve many layers
of abstraction. It might be useful to the OP one day to learn how to use
FileStream and similar objects to handle file i/o. But if all they need
to do at the moment is save some data to the disk and they have no
external criteria defining the file format, I see no need at that moment
to go any further than the built-in object serialization mechanisms.

Binary serialization is not a good choice for on disk storage (way too
many have been burnt when data structure change).

XML serialization is OK for disk storage.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top