so i'm new @ making apps (or gui programs in general) felt take on challenge i'm decently adept @ python , vba. i'm trying make visual schedule builder app university using windows 8 app running in c# , xaml. data courses split .csv files, 1 each department make searching easier. these files included in assets of app don't want have figure out how host data remotely right (unless make task easier).
i'm having trouble extracting data these files app. in app there 2 comboboxes i'm working on. 1 department , 1 courses within department, such mech 2202 specific class in mechanical engineering. want when first combo selected mech, second combo populates different course codes in department in single .csv file. more details used later when course code chosen there's several sections each, though can figured out later.
the relevant xaml testing purposes following. numbers populating second box 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, of mechanical engineering courses located in single .csv file named "course list_mech.csv" located in assets of app. data structured follows:
department,course_code,[several other non-relevant fields] my c# code far event after department has been chosen 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 code functions extract chosen department , goes testing textblock make sure it's working. wouldn't have trouble formatting file name locate correct department's file. problem after comment broken , doesn't work. pulled piece reading csv file , storing values array. i'm not adept enough @ c# see why it's not compiling. says "the name 'file' not exist in current context". once have course codes array i'm sure populate second combo box without trouble, it's getting data arrays (or lists might better) can't figure out.
any appreciated. have searched answer nothing clear enough me understand being new @ c# , no code snippets have worked.
if windows 8 app, cannot read directly path want , less c:. have use fileopenpicker have access files
var picker = new fileopenpicker() { suggestedstartlocation = pickerlocationid.documentslibrary}; picker.filtertype.add(".csv"); var file = await picker.picksinglefileasync(); if(file!=null) { var content = await fileio.readtextasync(file); } and can process content, can split first '\r' or instead fileio use streamreader.
it possible read files inside project, add csv file content ,
string filepath = @"ms-appx:///test.csv"; storagefile file = await storagefile.getfilefromapplicationuriasync(new uri(filepath)); var content = await fileio.readtextasync(file); and process file
Comments
Post a Comment