Click here to Skip to main content
15,949,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi i am looking to code eventComboBox_SelectedIndexChanged which handles ComboBox's SelectedIndexChanged event.This method will get the event selected in the ComboBox and display time, price and description of event in the Description TextBox.These items are all seperated by a comma in a text file, here is my code so far, any help would be great:
C#
private void CreateEventList()
{
    CommnunityEvents = new List<community_event>();
    // call the extract Data method.
    ExtractData();

    if (CommnunityEvents.Count > 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 21:48pm
v2
Comments
Sinisa Hajnal 25-Feb-15 4:30am    
And what is the problem? Text file in this case is not relevant since you're parsing it into a collection which you should use. You wrote everything well, now just select the fields you need based on eventComboBox selected value.
Rajesh Kariyavula 25-Feb-15 8:35am    
I see no issues with your code except that I didn't find where you are filling the comboBox and no implementation in SelectedIndexChanged event. What are you looking for exactly?
Member 11475948 25-Feb-15 9:22am    
Hi thanks for the reply, i have added some more code around the combo box control which i think should take the event(s)and populate the combo box with the data but i do not seem to be able to retrieve any info, any help would be great.thanks
//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();
eventComboBox.Items.Clear();
foreach (Community_Event item in CommnunityEvents)
{
eventComboBox.Items.Add(item.Description);
}
if (CommnunityEvents.Count > 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());
if (items.Length >= 5)
{
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.Add(newEvent);
}

}
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();
}
}
}

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