Click here to Skip to main content
15,891,692 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi i am looking to retrieve events from a text file i created with one form and trying to display them in another. if I select a date from the calendar on the second form I need the event name to be displayed in a combo box and if i select the event in the combo box the description and the price and time etc of the event appear in the textbox. i have created a community event class that is getting and setting the values. ant help would be great, here is what i have so far
C#
public partial class TicketInformationForm : Form
{ 
  public TicketInformationForm()
  {
     InitializeComponent();
  
  }
  //creating the community events list.
  List<community_event> CommnunityEvents;

  //create the Create Event list method.
  private void CreateEventList()
  {
     CommnunityEvents = new List<community_event>();
     // call the extract Data method.
     ExtractData();

     if (CommnunityEvents.Count &gt; 0)
     {
        //if there are no events for the date selected display the following
        eventComboBox.Text = " -Events- ";
        descriptionTextBox.Text = "Pick an event";
     }
     else
     {
        //if there are no events for the date selected display the following
        eventComboBox.Text = " No Events ";
        descriptionTextBox.Text = "No events today.";
     }
     
  }
  //Assignment 4 Part 2 – Create Method ExtractData
  private void ExtractData()
  {
     CommnunityEvents.Clear();

     // load the data from the file
     List<community_event> tempList = new List<community_event>();
     //string[] fileLines = File.ReadLines(@"C:\Users\IAN\Documents\calendar.txt");

     foreach(string line in File.ReadLines("Calendar.txt"))
     {
        string[] items = line.Split(",".ToCharArray());
           Community_Event newEvent = new Community_Event();
           newEvent.Day = Convert.ToInt32(items[0]);//Converting the Integer to a string.
           newEvent.Time = items[1];
           newEvent.Price = Convert.ToDecimal(items[2]);//Converting the decimal to a string.
           newEvent.Event = items[3];
           newEvent.Description = items[4];
     }
     CommnunityEvents = (from ev in tempList
                                  where ev.Day == 1
                                  select ev).ToList();
  }

  private void dateMonthCalendar_DateChanged(object sender, DateRangeEventArgs e)
  {
     //calling the create event list method to display any events in the eventscombo box.
     CreateEventList();
  }
  
  private void eventComboBox_SelectedIndexChanged(object sender, EventArgs e)
  {
    /*display time, price and desription of any events selected in the combo box and display them
     in the description TextBox*/
     
  }
  private void descriptionTextBox_TextChanged(object sender, EventArgs e)
  {
    
  }
  private void TicketInformationForm_Load(object sender, EventArgs e)
  {
     //calling the create event list to open the form with today's events displayed if any.
     CreateEventList();
  }
}
Posted
Updated 24-Feb-15 3:45am
v3
Comments
ZurdoDev 24-Feb-15 9:49am    
Where are you stuck?

1 solution

Nothing in that code shows you using a text file: and if you are, you probably shouldn't unless it's for something other than just transferring information from one form to another.

If what you are trying to do is select a date on Form2 and get it to affect what is shown on Form1 then that's pretty easy, but exactly how you do it depends on the relationship between the forms.
If Form1 creates the instance of Form2: Transferring information between two forms, Part 2: Child to Parent[^]
If Form2 creates the instance of Form1: Transferring information between two forms, Part 1: Parent to Child[^]
If both Form1 and Form2 are created by a different form (Form3): Transferring information between two forms, Part 3: Child to Child[^]

If that isn't what you are talking about, then you need to clarify your question and provide more detail!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900