0

well guys , i want to make a read and write from textfile ...
but the problem is when i click the calendar, and click create now(button 1), it cant work... if i didnt click the calendar, it works well.. so how to solve this problem anyone?

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;
using System.IO;

namespace Timetable
{
    public partial class Form1 : Form
    {
        private string[,] m_strdata = new string[11, 5];//11-events, 5[m_intNumberOfEvents]
        private int m_intNumberOfEvents;
        //write the text to a file
        private StreamWriter m_objOutput = File.AppendText("1.txt");// add line to write instead of rewrite
        //initalize StreamReader to read from file
        StreamReader objInput;

        private void CreateEventList()
        {
            int intCount;
            //stores event info in array m_strdata
            ExtractData(mvwDate.SelectionStart);
            //remove combobox items
            cboevent.Items.Clear();
            //add each new event name to comboBox
           
            if (m_intNumberOfEvents > 0)
            {
                for (intCount = 0; intCount < m_intNumberOfEvents;
                    intCount++)
                {
                    //extract and display event name
                    cboevent.Items.Add(m_strdata[intCount, 3]);//1-time,2- price,3- name,4-description
                }
                //inform user that events are scheduled
                cboevent.Text = "- " + Convert.ToString(m_intNumberOfEvents) + " Events found -";
                txtDescription.Text = "Pick an event.";
            }

            //inform user that no events are scheduled
            else
            {
                cboevent.Text = "-No Events-";
                txtDescription.Text = "No events today";
            }
        } // end method CreateEventList

        // extracts event data for a specified day from calendar.txt
        // and returns number of events during that day
        private void ExtractData(DateTime dtmDay)
        {
            //set to selected date in Mobthalendar control
            int intChosenDay = dtmDay.Day;
            int intFileDay;//day of event from file
            int intLineNumbers;//counts lines to skip
            objInput = new StreamReader("calendar.txt");
            m_intNumberOfEvents = 0;//set number of events to 0
            //read first line  before entering loop
            string strline = objInput.ReadLine();

            //loop though lines in file
            while (objInput.Peek() > -1 &&
                m_intNumberOfEvents < 11)//11-events
            {
                intFileDay = Int32.Parse(strline);//extract day
                //if event scheduled for specified day,
                //store information
                if (intFileDay == intChosenDay)
                {
                    m_strdata[m_intNumberOfEvents, 0] = strline;
                    m_strdata[m_intNumberOfEvents, 1] = objInput.ReadLine();
                    m_strdata[m_intNumberOfEvents, 2] = objInput.ReadLine();
                    m_strdata[m_intNumberOfEvents, 3] = objInput.ReadLine();
                    m_strdata[m_intNumberOfEvents, 4] = objInput.ReadLine();
                    //m_strdata[m_intNumberOfEvents, 5] = objInput.ReadLine();//sensitive-5 lines
                    m_intNumberOfEvents++;
                }
                else
                {
                    //skip to next event in file 
                    for (intLineNumbers = 0; intLineNumbers <= 3; intLineNumbers++)//<=4-5 lines
                        strline = objInput.ReadLine();
                }
                //read day of next events in file
                strline = objInput.ReadLine();
            }//end while 
        }
        public Form1()
        {
            InitializeComponent();
        }
        // populates ComboBox with current day's events (if any)
        
        private void Form1_Load(object sender, EventArgs e)
        {
            CreateEventList();
            btncreate.Enabled = false;
            txtcost.Enabled = false;
            txtday.Enabled = false;
            txtname.Enabled = false;
            txttime.Enabled = false;
            txtwritedescription.Enabled = false;
        }

        private void mvwDate_DateChanged(object sender, DateRangeEventArgs e)
        {
            //displayed any events for the specified date in ComboBox
            CreateEventList();
        }

        private void cboevent_SelectedIndexChanged(object sender, EventArgs e)
        {
            //place time, price and desciption of event in textbox
            txtDescription.Text =
                m_strdata[cboevent.SelectedIndex, 1];
            txtDescription.Text += "\r\n" +"$"+
              m_strdata[cboevent.SelectedIndex, 2];
            txtDescription.Text += "\r\n" +
                m_strdata[cboevent.SelectedIndex, 4];
        }
        private void clearuserinput()
         {
            txtcost.Clear();
            txtday.Clear();
            txtname.Clear();
            txttime.Clear();
            txtwritedescription.Clear();
        }
        private void btncreate_Click(object sender, EventArgs e)
        {  
              m_objOutput.WriteLine(txtday.Text);
              m_objOutput.WriteLine(txttime.Text);
              m_objOutput.WriteLine(txtcost.Text);
              m_objOutput.WriteLine(txtname.Text);
              m_objOutput.WriteLine(txtwritedescription.Text);
              clearuserinput();
              objInput.Close();
              m_objOutput.Close();
              m_objOutput = File.AppendText("1.txt");
              objInput = new StreamReader("calendar.txt");
        }

        private void button1_Click(object sender, EventArgs e)
        {
            objInput.Close();
            m_objOutput.Close();
            objInput = new StreamReader("1.txt");
            m_objOutput = File.AppendText("calendar.txt");
            btncreate.Enabled = true;
            txtcost.Enabled = true;
            txtday.Enabled = true;
            txtname.Enabled = true;
            txttime.Enabled = true;
            txtwritedescription.Enabled =true;
        }
    }
}
2
Contributors
6
Replies
8
Views
6 Years
Discussion Span
Last Post by Lowchernhwee
0

well i think when i click the dates of the calendar, it uses the data from calendar.txt ....
so is there other ways of closing the thing(temporary)? or add some codes to overight the codes?

0

well i tried it sort of worked....
the problem is that if i clicked the days twice from the calendar, it doesnt worked...
so how to solve this?

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;
using System.IO;

namespace Timetable
{
    public partial class Form1 : Form
    {
        private string[,] m_strdata = new string[11, 5];//11-events, 5[m_intNumberOfEvents]
        private int m_intNumberOfEvents;
        //write the text to a file
        private StreamWriter m_objOutput = File.AppendText("1.txt");// add line to write instead of rewrite
        //initalize StreamReader to read from file
        StreamReader objInput;
        int x=0;

        private void CreateEventList()
        {
            int intCount;
            //stores event info in array m_strdata
            ExtractData(mvwDate.SelectionStart);
            //remove combobox items
            cboevent.Items.Clear();
            //add each new event name to comboBox
           
            if (m_intNumberOfEvents > 0)
            {
                for (intCount = 0; intCount < m_intNumberOfEvents;
                    intCount++)
                {
                    //extract and display event name
                    cboevent.Items.Add(m_strdata[intCount, 3]);//1-time,2- price,3- name,4-description
                }
                //inform user that events are scheduled
                cboevent.Text = "- " + Convert.ToString(m_intNumberOfEvents) + " Events found -";
                txtDescription.Text = "Pick an event.";
            }

            //inform user that no events are scheduled
            else
            {
                cboevent.Text = "-No Events-";
                txtDescription.Text = "No events today";
            }
        } // end method CreateEventList

        // extracts event data for a specified day from calendar.txt
        // and returns number of events during that day
        private void ExtractData(DateTime dtmDay)
        {
            //set to selected date in Mobthalendar control
            int intChosenDay = dtmDay.Day;
            int intFileDay;//day of event from file
            int intLineNumbers;//counts lines to skip
            objInput = new StreamReader("calendar.txt");
            m_intNumberOfEvents = 0;//set number of events to 0
            //read first line  before entering loop
            string strline = objInput.ReadLine();

            //loop though lines in file
            while (objInput.Peek() > -1 &&
                m_intNumberOfEvents < 11)//11-events
            {
                x = 1; 
                intFileDay = Int32.Parse(strline);//extract day
                //if event scheduled for specified day,
                //store information
                if (intFileDay == intChosenDay)
                {
                    m_strdata[m_intNumberOfEvents, 0] = strline;
                    m_strdata[m_intNumberOfEvents, 1] = objInput.ReadLine();
                    m_strdata[m_intNumberOfEvents, 2] = objInput.ReadLine();
                    m_strdata[m_intNumberOfEvents, 3] = objInput.ReadLine();
                    m_strdata[m_intNumberOfEvents, 4] = objInput.ReadLine();
                    //m_strdata[m_intNumberOfEvents, 5] = objInput.ReadLine();//sensitive-5 lines
                    m_intNumberOfEvents++;
                }
                else
                {
                    //skip to next event in file 
                    for (intLineNumbers = 0; intLineNumbers <= 3; intLineNumbers++)//<=4-5 lines
                        strline = objInput.ReadLine();
                }
                //read day of next events in file
                strline = objInput.ReadLine();
                
            }//end while 
        }
        public Form1()
        {
            InitializeComponent();
        }
        // populates ComboBox with current day's events (if any)
        
        private void Form1_Load(object sender, EventArgs e)
        {
            //CreateEventList();- unable to use for this program
            btncreatelater.Enabled = false;
            btncreatenow.Enabled = false;
            btnclear.Enabled = false;
            txtcost.Enabled = false;
            updDay.Enabled = false;
            txtname.Enabled = false;
            dtpTime.Enabled = false;
            txtwritedescription.Enabled = false;
        }

        private void cboevent_SelectedIndexChanged(object sender, EventArgs e)
        {
            //place time, price and desciption of event in textbox
            txtDescription.Text =
                m_strdata[cboevent.SelectedIndex, 1];
            txtDescription.Text += "\r\n" +"$"+
              m_strdata[cboevent.SelectedIndex, 2];
            txtDescription.Text += "\r\n" +
                m_strdata[cboevent.SelectedIndex, 4];
        }
        private void clearuserinput()
         {
            txtcost.Clear();
            txtname.Clear();
            updDay.Text = ("1");
            dtpTime.Text=("12:00 AM");
            txtwritedescription.Clear();
            txtcost.Enabled = false;
            updDay.Enabled = false;
            txtname.Enabled = false;
            dtpTime.Enabled = false;
            txtwritedescription.Enabled = false;
        }
        private void btncreate_Click(object sender, EventArgs e)
        {
              mvwDate.Enabled = true;
              btncreatenew.Enabled = true;
              btncreatenow.Enabled = false;
              btnclear.Enabled = false;
              m_objOutput.WriteLine(updDay.Text);
              m_objOutput.WriteLine(dtpTime.Text);
              m_objOutput.WriteLine(txtcost.Text);
              m_objOutput.WriteLine(txtname.Text);
              m_objOutput.WriteLine(txtwritedescription.Text);
              objInput.Close();
              m_objOutput.Close();
              m_objOutput = File.AppendText("2.txt");
              x = 0;
              clearuserinput();//disable , clearing to clear away the datas and to prevent errors
              //eg application is being used by others...
              cboevent.Enabled = true;
              txtDescription.Enabled = true;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (x == 1)
            {
                objInput.Dispose();
                objInput.Close(); 
            }//insurance that got 2 choices
            //1-read then create , have to close objinput
            //0-create, dun have to close objinput
            /********************************************/
            //remove combobox items
            cboevent.Items.Clear();
            cboevent.Text = "";
            cboevent.Enabled = false;
            mvwDate.Enabled = false;
            txtDescription.Clear();
            txtDescription.Enabled = false;
            /*********************************************/
            //disable , clearing and overwriting to clear away the datas and to prevent errors
            //eg application is being used by others...
            m_objOutput.Close();
            objInput = new StreamReader("1.txt");
            m_objOutput = File.AppendText("calendar.txt");
            btncreatelater.Enabled = true;
            btncreatenew.Enabled = false;
            btncreatenow.Enabled = true;
            btnclear.Enabled = true;
            txtcost.Enabled = true;
            updDay.Enabled = true;
            txtname.Enabled = true;
            dtpTime.Enabled = true;
            txtwritedescription.Enabled =true;
        }

        private void btnclear_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Warming, doing this will erase all the data that is stored inside the calendar!!!",
            "Clear", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
            {
                m_objOutput.Close();
                objInput = new StreamReader("1.txt");
                m_objOutput = new StreamWriter("calendar.txt");
                m_objOutput.Write("");
                m_objOutput.Close();
            }
            else 
            {
                MessageBox.Show("You have make the right choice ^_^.");
            }
        }

        private void mvwDate_DateSelected(object sender, DateRangeEventArgs e)
        {
            //displayed any events for the specified date in ComboBox
            CreateEventList();
        }

        private void btncreatelater_Click(object sender, EventArgs e)
        {
          
            btncreatelater.Enabled = false;
            btnclear.Enabled = false;
            btncreatenow.Enabled = false;
            btncreatenew.Enabled = true;
            mvwDate.Enabled = true;
            objInput.Close();
            m_objOutput.Close();
            m_objOutput = File.AppendText("2.txt");
            x = 1;
            clearuserinput();//disable , clearing to clear away the datas and to prevent errors
            //eg application is being used by others...
            cboevent.Enabled = true;
            txtDescription.Enabled = true;
        }
    }
}

added some new features like clear and create later...

0

well i tried and edit some .. it works perfect

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;
using System.IO;

namespace Timetable
{
    public partial class Form1 : Form
    {
        private string[,] m_strdata = new string[11, 5];//11-events, 5[m_intNumberOfEvents]
        private int m_intNumberOfEvents;
        //write the text to a file
        private StreamWriter objOutput = File.AppendText("1.txt");// add line to write instead of rewrite
        //initalize StreamReader to read from file
        StreamReader objInput;

        private void CreateEventList()
        {
            int intCount;
            //stores event info in array m_strdata
            ExtractData(mvwDate.SelectionStart);
            //remove combobox items
            cboevent.Items.Clear();
            //add each new event name to comboBox
           
            if (m_intNumberOfEvents > 0)
            {
                for (intCount = 0; intCount < m_intNumberOfEvents;
                    intCount++)
                {
                    //extract and display event name
                    cboevent.Items.Add(m_strdata[intCount, 3]);//1-time,2- price,3- name,4-description
                }
                //inform user that events are scheduled
                cboevent.Text = "- " + Convert.ToString(m_intNumberOfEvents) + " Events found -";
                txtDescription.Text = "Pick an event.";
            }

            //inform user that no events are scheduled
            else
            {
                cboevent.Text = "-No Events-";
                txtDescription.Text = "No events today";
            }
        } // end method CreateEventList

        // extracts event data for a specified day from calendar.txt
        // and returns number of events during that day
        private void ExtractData(DateTime dtmDay)
        {
            //set to selected date in Mobthalendar control
            int intChosenDay = dtmDay.Day;
            int intFileDay;//day of event from file
            int intLineNumbers;//counts lines to skip
            objInput = new StreamReader("calendar.txt");
            m_intNumberOfEvents = 0;//set number of events to 0
            //read first line  before entering loop
            string strline = objInput.ReadLine();

            //loop though lines in file
            while (objInput.Peek() > -1 &&
                m_intNumberOfEvents < 11)//11-events
            {
                
                intFileDay = Int32.Parse(strline);//extract day
                //if event scheduled for specified day,
                //store information
                if (intFileDay == intChosenDay)
                {
                    m_strdata[m_intNumberOfEvents, 0] = strline;
                    m_strdata[m_intNumberOfEvents, 1] = objInput.ReadLine();
                    m_strdata[m_intNumberOfEvents, 2] = objInput.ReadLine();
                    m_strdata[m_intNumberOfEvents, 3] = objInput.ReadLine();
                    m_strdata[m_intNumberOfEvents, 4] = objInput.ReadLine();
                    //m_strdata[m_intNumberOfEvents, 5] = objInput.ReadLine();//sensitive-5 lines
                    m_intNumberOfEvents++;
                }
                else
                {
                    //skip to next event in file 
                    for (intLineNumbers = 0; intLineNumbers <= 3; intLineNumbers++)//<=4-5 lines
                        strline = objInput.ReadLine();
                }
                //read day of next events in file
                strline = objInput.ReadLine();
            }//end while
            objInput.Dispose();//to prevent open txt file X times of the clicking of calendar dates.
        }
        public Form1()
        {
            InitializeComponent();
        }
        
        private void Form1_Load(object sender, EventArgs e)
        {
            CreateEventList();
            btncreatelater.Enabled = false;
            btncreatenow.Enabled = false;
            btnclear.Enabled = false;
            txtcost.Enabled = false;
            updDay.Enabled = false;
            txtname.Enabled = false;
            dtpTime.Enabled = false;
            txtwritedescription.Enabled = false;
        }

        private void cboevent_SelectedIndexChanged(object sender, EventArgs e)
        {
            //place time, price and desciption of event in textbox
            txtDescription.Text =
                m_strdata[cboevent.SelectedIndex, 1];
            txtDescription.Text += "\r\n" +"$"+
              m_strdata[cboevent.SelectedIndex, 2];
            txtDescription.Text += "\r\n" +
                m_strdata[cboevent.SelectedIndex, 4];
        }
        private void clearuserinput()
         {
            txtcost.Clear();
            txtname.Clear();
            updDay.Text = ("1");
            dtpTime.Text=("12:00 AM");
            txtwritedescription.Clear();
            txtcost.Enabled = false;
            updDay.Enabled = false;
            txtname.Enabled = false;
            dtpTime.Enabled = false;
            txtwritedescription.Enabled = false;
        }
        private void btncreate_Click(object sender, EventArgs e)
        {
              mvwDate.Enabled = true;
              btncreatenew.Enabled = true;
              btncreatenow.Enabled = false;
              btnclear.Enabled = false;
              btncreatelater.Enabled = false;
              objOutput.WriteLine(updDay.Text);
              objOutput.WriteLine(dtpTime.Text);
              objOutput.WriteLine(txtcost.Text);
              objOutput.WriteLine(txtname.Text);
              objOutput.WriteLine(txtwritedescription.Text);
              objInput.Close();
              objOutput.Close();
              objOutput = File.AppendText("1.txt");
              clearuserinput();//disable , clearing to clear away the datas and to prevent errors
              //eg application is being used by others...
              cboevent.Enabled = true;
              txtDescription.Enabled = true;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            
            /********************************************/
            //remove combobox items
            cboevent.Items.Clear();
            cboevent.Text = "";
            cboevent.Enabled = false;
            mvwDate.Enabled = false;
            txtDescription.Clear();
            txtDescription.Enabled = false;
            /*********************************************/
            //disable , clearing and overwriting to clear away the datas and to prevent errors
            //eg application is being used by others...
            objOutput.Close();
            objInput = new StreamReader("1.txt");
            objInput.Close();
            objOutput = File.AppendText("calendar.txt");
            btncreatelater.Enabled = true;
            btncreatenew.Enabled = false;
            btncreatenow.Enabled = true;
            btnclear.Enabled = true;
            txtcost.Enabled = true;
            updDay.Enabled = true;
            txtname.Enabled = true;
            dtpTime.Enabled = true;
            txtwritedescription.Enabled =true;
        }

        private void btnclear_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Warming, doing this will erase all the data that is stored inside the calendar!!!",
            "Clear", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
            {
                objOutput.Close();
                objInput = new StreamReader("1.txt");
                objOutput = new StreamWriter("calendar.txt");//overwriting
                objOutput.Write("");
                objInput.Close();
                objOutput.Close();
                MessageBox.Show("Data cleared.");
            }
            else 
            {
                MessageBox.Show("You have make the right choice ^_^.");
            }
        }

        private void mvwDate_DateSelected(object sender, DateRangeEventArgs e)
        {
            //displayed any events for the specified date in ComboBox
            CreateEventList();
        }

        private void btncreatelater_Click(object sender, EventArgs e)
        {
          
            btncreatelater.Enabled = false;
            btnclear.Enabled = false;
            btncreatenow.Enabled = false;
            btncreatenew.Enabled = true;
            mvwDate.Enabled = true;
            objOutput.Dispose();
            objOutput.Close();
            objInput = new StreamReader("calendar.txt");
            objInput.Close();
            objOutput = File.AppendText("1.txt");
            clearuserinput();//disable , clearing to clear away the datas and to prevent errors
            //eg application is being used by others...
            cboevent.Enabled = true;
            txtDescription.Enabled = true;
        }
    }
}

//objInput = new StreamReader("calendar.txt");
//objOutput = File.AppendText("1.txt");
//objInput = new StreamReader("1.txt");
//objOutput = File.AppendText("calendar.txt");
//these codes are just to swap places so that the users can key and read at the same txt file("calendar.txt").
0

sry i remodified again..
this time sure works 99%(1% maybe contain some error which i may leftout during the test run...)

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;
using System.IO;

namespace Timetable
{
    public partial class Form1 : Form
    {
        private string[,] m_strdata = new string[11, 5];//11-events, 5[m_intNumberOfEvents]
        private int m_intNumberOfEvents;
        //write the text to a file
        private StreamWriter objOutput = File.AppendText("1.txt");// add line to write instead of rewrite
        //initalize StreamReader to read from file
        StreamReader objInput;

        private void CreateEventList()
        {
            int intCount;
            //stores event info in array m_strdata
            ExtractData(mvwDate.SelectionStart);
            //remove combobox items
            cboevent.Items.Clear();
            //add each new event name to comboBox
           
            if (m_intNumberOfEvents > 0)
            {
                for (intCount = 0; intCount < m_intNumberOfEvents;
                    intCount++)
                {
                    //extract and display event name
                    cboevent.Items.Add(m_strdata[intCount, 3]);//1-time,2- price,3- name,4-description
                }
                //inform user that events are scheduled
                cboevent.Text = "- " + Convert.ToString(m_intNumberOfEvents) + " Events found -";
                txtDescription.Text = "Pick an event.";
            }

            //inform user that no events are scheduled
            else
            {
                cboevent.Text = "-No Events-";
                txtDescription.Text = "No events today";
            }
        } // end method CreateEventList

        // extracts event data for a specified day from calendar.txt
        // and returns number of events during that day
        private void ExtractData(DateTime dtmDay)
        {
            //set to selected date in Mobthalendar control
            int intChosenDay = dtmDay.Day;
            int intFileDay;//day of event from file
            int intLineNumbers;//counts lines to skip
            objInput = new StreamReader("calendar.txt");
            m_intNumberOfEvents = 0;//set number of events to 0
            //read first line  before entering loop
            string strline = objInput.ReadLine();

            //loop though lines in file
            while (objInput.Peek() > -1 &&
                m_intNumberOfEvents < 11)//11-events
            {
                
                intFileDay = Int32.Parse(strline);//extract day
                //if event scheduled for specified day,
                //store information
                if (intFileDay == intChosenDay)
                {
                    m_strdata[m_intNumberOfEvents, 0] = strline;
                    m_strdata[m_intNumberOfEvents, 1] = objInput.ReadLine();
                    m_strdata[m_intNumberOfEvents, 2] = objInput.ReadLine();
                    m_strdata[m_intNumberOfEvents, 3] = objInput.ReadLine();
                    m_strdata[m_intNumberOfEvents, 4] = objInput.ReadLine();
                    //m_strdata[m_intNumberOfEvents, 5] = objInput.ReadLine();//sensitive-5 lines
                    m_intNumberOfEvents++;
                }
                else
                {
                    //skip to next event in file 
                    for (intLineNumbers = 0; intLineNumbers <= 3; intLineNumbers++)//<=4-5 lines
                        strline = objInput.ReadLine();
                }
                //read day of next events in file
                strline = objInput.ReadLine();
            }//end while
            objInput.Dispose();//to prevent open txt file X times of the clicking of calendar dates.
        }
        public Form1()
        {
            InitializeComponent();
        }
        
        private void Form1_Load(object sender, EventArgs e)
        {
            //CreateEventList();
            btncreatelater.Enabled = false;
            btncreatenow.Enabled = false;
            btnclear.Enabled = false;
            txtcost.Enabled = false;
            updDay.Enabled = false;
            txtname.Enabled = false;
            dtpTime.Enabled = false;
            txtwritedescription.Enabled = false;
        }

        private void cboevent_SelectedIndexChanged(object sender, EventArgs e)
        {
            //place time, price and desciption of event in textbox
            txtDescription.Text =
                m_strdata[cboevent.SelectedIndex, 1];
            txtDescription.Text += "\r\n" +"$"+
              m_strdata[cboevent.SelectedIndex, 2];
            txtDescription.Text += "\r\n" +
                m_strdata[cboevent.SelectedIndex, 4];
        }
        private void clearuserinput()
         {
            txtcost.Clear();
            txtname.Clear();
            updDay.Text = ("1");
            dtpTime.Text=("12:00 AM");
            txtwritedescription.Clear();
            txtcost.Enabled = false;
            updDay.Enabled = false;
            txtname.Enabled = false;
            dtpTime.Enabled = false;
            txtwritedescription.Enabled = false;
        }
        private void btncreate_Click(object sender, EventArgs e)
        {
              objOutput = File.AppendText("calendar.txt");
              mvwDate.Enabled = true;
              btncreatenew.Enabled = true;
              btncreatenow.Enabled = false;
              btnclear.Enabled = false;
              btncreatelater.Enabled = false;
              objOutput.WriteLine(updDay.Text);
              objOutput.WriteLine(dtpTime.Text);
              objOutput.WriteLine(txtcost.Text);
              objOutput.WriteLine(txtname.Text);
              objOutput.WriteLine(txtwritedescription.Text);
              objInput.Close();
              objOutput.Close();
              objOutput = File.AppendText("1.txt");
              clearuserinput();//disable , clearing to clear away the datas and to prevent errors
              //eg application is being used by others...
              cboevent.Enabled = true;
              txtDescription.Enabled = true;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            
            /********************************************/
            //remove combobox items
            cboevent.Items.Clear();
            cboevent.Text = "";
            cboevent.Enabled = false;
            mvwDate.Enabled = false;
            txtDescription.Clear();
            txtDescription.Enabled = false;
            /*********************************************/
            //disable , clearing and overwriting to clear away the datas and to prevent errors
            //eg application is being used by others...
            objOutput.Close();
            objInput = new StreamReader("1.txt");
            objInput.Close();
            btncreatelater.Enabled = true;
            btncreatenew.Enabled = false;
            btncreatenow.Enabled = true;
            btnclear.Enabled = true;
            txtcost.Enabled = true;
            updDay.Enabled = true;
            txtname.Enabled = true;
            dtpTime.Enabled = true;
            txtwritedescription.Enabled =true;
        }

        private void btnclear_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Warming, doing this will erase all the data that is stored inside the calendar!!!",
            "Clear", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
            {
                objInput = new StreamReader("1.txt");
                objOutput = new StreamWriter("calendar.txt");//overwriting
                objOutput.Write("");
                objInput.Close();
                objOutput.Close();
                MessageBox.Show("Data cleared.");
            }
            else 
            {
                MessageBox.Show("You have make the right choice ^_^.");
            }
        }

        private void mvwDate_DateSelected(object sender, DateRangeEventArgs e)
        {
            //displayed any events for the specified date in ComboBox
            CreateEventList();
        }

        private void btncreatelater_Click(object sender, EventArgs e)
        {
          
            btncreatelater.Enabled = false;
            btnclear.Enabled = false;
            btncreatenow.Enabled = false;
            btncreatenew.Enabled = true;
            mvwDate.Enabled = true;
            objOutput.Dispose();
            objOutput.Close();
            objInput = new StreamReader("calendar.txt");
            objInput.Close();
            objOutput = File.AppendText("1.txt");
            clearuserinput();//disable , clearing to clear away the datas and to prevent errors
            //eg application is being used by others...
            cboevent.Enabled = true;
            txtDescription.Enabled = true;
        }
    }
}

//objInput = new StreamReader("calendar.txt");
//objOutput = File.AppendText("1.txt");
//objInput = new StreamReader("1.txt");
//objOutput = File.AppendText("calendar.txt");
//these codes are just to swap places so that the users can key and read at the same txt file("calendar.txt").
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.