So I'm very new at making apps (or GUI programs in general) but I felt like I could take on this challenge as I'm decently adept at python and VBA. I'm trying to make a visual schedule builder app for my university using a windows 8 app running in C# and xaml. The data for all courses is split up into .csv files, one for each department to make searching easier. These files are to be included in the assets of the app itself as I don't want to have to figure out how to host the data remotely right now (unless that would make this task easier).
I'm having trouble extracting the data from these files into my app. In my app there are currently two comboboxes that I'm working on. One for the department and one for the courses within that department, such as MECH 2202 for a specific class in mechanical engineering. I want that when the first combo is selected for MECH, the second combo populates with all different course codes in that department which are in a single .csv file. More details would be used later when the course code is chosen as there's several sections for each, though that can be figured out later.
The relevant xaml for testing purposes is the following. The numbers populating the second box are just temporary.
<ComboBox x:Name="departmentCombo" HorizontalAlignment="Center" Margin="0" Grid.Row="1" VerticalAlignment="Center" Width="100" Height="40" MaxDropDownHeight="400" SelectionChanged="DepartmentChange">
<ComboBoxItem Content="BIOE"/>
<ComboBoxItem Content="CIVL"/>
<ComboBoxItem Content="ECE"/>
<ComboBoxItem Content="ENG"/>
<ComboBoxItem Content="MECH"/>
</ComboBox>
<ComboBox x:Name="courseCombo" HorizontalAlignment="Center" Margin="0" Grid.Row="1" VerticalAlignment="Center" Width="100" Height="40" MaxDropDownHeight="400">
<ComboBoxItem Content="2012"/>
<ComboBoxItem Content="2202"/>
<ComboBoxItem Content="3542"/>
<ComboBoxItem Content="3582"/>
<ComboBoxItem Content="3980"/>
</ComboBox>
For example, all of the mechanical engineering courses are located in a single .csv file named "Course List_MECH.csv" located in the assets of the app. The data is structured as follows:
department,course_code,[several other non-relevant fields]
My C# code so far for the event after a department has been chosen is this:
private void DepartmentChange(object sender, SelectionChangedEventArgs e)
{
ComboBoxItem typeItem = (ComboBoxItem)departmentCombo.SelectedItem;
string department_str = typeItem.Content.ToString();
testText.Text = department_str;
///broken
var reader = new StreamReader(File.OpenRead(@"C:\test.csv"));
List<string> listA = new List<string>();
List<string> listB = new List<string>();
while (!reader.EndOfStream)
{
var line = reader.ReadLine();
var values = line.Split(';');
listA.Add(values[0]);
listB.Add(values[1]);
}
}
The first part of this code functions to extract the chosen department and goes into a testing textblock to make sure it's working. So I wouldn't have any trouble formatting the file name to locate the correct department's file. Problem is everything after the comment is broken and doesn't work. I pulled this piece from Reading CSV file and storing values into an array. I'm not adept enough at C# to see why it's not even compiling. It says that "The name 'File' does not exist in the current context". Once I have all the course codes into an array I'm sure I could get it to populate the second combo box without too much trouble, it's getting the data into those arrays (or lists might be better) that I can't figure out.
Any help would be greatly appreciated. I have searched for an answer to this but nothing I get is clear enough for me to understand being new at C# and no code snippets have worked.