c# - How can I populate comboboxes from arrays? -
i text file names , phone numbers. lecturer gave me piece of code split 2 arrays. i'm having trouble populating name , phone number comboboxes these arrays. errors saying array1 , array2 don't exist in current context. how can correctly?
here relevent part of code;
public partial class mainwindow : window { private string cfilename = "customer.txt"; private string[] cnames = new string[0]; private string[] cphonenumbers = new string[0];
public mainwindow() { initializecomponent(); this.loaded += new routedeventhandler(window_loaded); } private void read_delimited_file(string filename, ref string[] array1, ref string[] array2) { streamreader filesr = new streamreader(filename); char[] delimiters = { ',' }; string[] temparray = new string[0]; string line = filesr.readline(); while (line != null) { array.resize(ref array1, array1.length + 1); array.resize(ref array2, array2.length + 1); temparray = line.split(delimiters); array1[array1.length - 1] = temparray[0]; array2[array2.length - 1] = temparray[1]; line = filesr.readline(); } filesr.close(); } private void window_loaded(object sender, routedeventargs e) { keyboard.focus(phonetextbox); read_delimited_file(cfilename, ref cnames, ref cphonenumbers); (int = 0; < array1.length; i++) { namecombobox.items.add(array1[i]); } (int = 0; < array2.length; i++) { phonenumbercombobox.items.add(array1[i]); } }
the variables array1
, array2
exist inside function scope.
you meant use cnames
, cphonenumbers
.
Comments
Post a Comment