Wrox Programmer Forums
BOOK: Stephens' C# Programming with Visual Studio 2010 24-Hour Trainer
This is the forum to discuss the Wrox book Stephens' C# Programming with Visual Studio 2010 24-Hour Trainer by Rod Stephens; ISBN: 9780470596906
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Stephens' C# Programming with Visual Studio 2010 24-Hour Trainer section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old May 20th, 2011, 10:43 PM
Registered User
Join Date: Apr 2011
Posts: 9
Thanks: 5
Thanked 0 Times in 0 Posts
Cool Saving my program

Hi there
Im trying diffrent things i have learnt so far but am struggling with saving
I have created 2 forms to save onto a main form. It is a simple service records program where i enter the Date, milage and type of service for each vehicle I have and save it to a main form where i can see where each vehicle is up to
The main form updates fine for the two vehicles but I cant work out where im going wrong in saving it
It goes through and asks me to save it, I give it a name, click save, it disapears then when i go into it Its not there
any idea on where i have gone wrong
here is the code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Car_Service
    public partial class serviceRecordsForm : Form
        public serviceRecordsForm()

        private void addNewRecordTyphoon_Click(object sender, EventArgs e)
            addNewRecordTyphoon newRecordTyphoonDialog;
            newRecordTyphoonDialog = new addNewRecordTyphoon();
            if (newRecordTyphoonDialog.ShowDialog() == DialogResult.OK)
                typhoonDateListBox.Items.Add    (newRecordTyphoonDialog.dateTyphoonRichTextBox.Text);


        private void addNewRecordCruiser_Click(object sender, EventArgs e)
            addNewRecordCruiser newRecordCruiserDialog;
            newRecordCruiserDialog = new addNewRecordCruiser();
            if (newRecordCruiserDialog.ShowDialog() == DialogResult.OK)


        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
            if (saveFileDialog.ShowDialog() == DialogResult.OK)
                cruiserDateListBox.Text = saveFileDialog.FileName;
                typhoonDateListBox.Text = saveFileDialog.FileName;
                cruiserOdoListBox.Text = saveFileDialog.FileName;
                typhoonOdoListBox.Text = saveFileDialog.FileName;
                cruiserServiceListBox.Text = saveFileDialog.FileName;
                typhoonServiceListBox.Text = saveFileDialog.FileName;


cheers Harold
Old May 21st, 2011, 10:18 AM
Rod Stephens's Avatar
Wrox Author
Join Date: Jan 2006
Posts: 647
Thanks: 2
Thanked 96 Times in 95 Posts

Do you mean you're trying to save the data into a file?

It looks like the code you have tries to write the name of the selected file into the ListBoxes.

Take a look at Lesson 29, "Reading and Writing Files." ListBoxes can hold lots of values so you'll need to loop through them when writing.

If you want to read the values back out of the file when the program starts, you'll need to know how many items are in each ListBox. To do that, you could start by writing the ListBox's number of items into the file. Here's the basic idea:

Write the number of items on its own line
foreach item in listbox.items
Write the item on its own line
Repeat for each ListBox

Read the number of items from a line
for i = 0; i < number read
Read a listbox item
Repeat for each ListBox

Give it a try to see how far you get and let us know how it goes.

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)
The Following User Says Thank You to Rod Stephens For This Useful Post:
harold4964 (May 21st, 2011)
Old May 21st, 2011, 10:56 AM
Registered User
Join Date: May 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default nice

iPhone 5
Old May 21st, 2011, 10:15 PM
Registered User
Join Date: Apr 2011
Posts: 9
Thanks: 5
Thanked 0 Times in 0 Posts

Thanks for that Rod
I will have a look at that lesson although I dont want to get too far ahead of my self
What im doing is making a program from the things I have learnt from you after the tutorials just to see if im grasping the idea and hopefully the end result will be something I can use

Thanks a bunch on your help


Similar Threads
Thread Thread Starter Forum Replies Last Post
Setup Project: Program not added in Start>Program arif_1947 VS.NET 2002/2003 2 March 31st, 2005 06:40 AM
EXCEL question saving a file saving the the first macupryk VS.NET 2002/2003 0 January 6th, 2005 05:33 PM
Start a program inside another program Silje Classic ASP Professional 1 November 16th, 2004 02:08 AM
How To avoid the SAving of toolbars while saving Hari_Word Excel VBA 6 July 26th, 2004 12:13 AM
Saving davidhowell1971 Excel VBA 1 March 1st, 2004 04:02 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.