Code for WPF
void OnClick2(object sender, RoutedEventArgs e) { B_Open.Background = Brushes.Pink; Userdata_DG1.ItemsSource=GetData(); // Gets ALL the data } // end onclick handler
public List<csvrow> GetData() { string line; // Read a file and display it line by line. csvlist = new List<csvrow>(); // create the list of rows System.IO.StreamReader myFile = new System.IO.StreamReader ("C:\\temp\\oscourse\\ListFile_in.txt"); while ((line = myFile.ReadLine()) != null) process_line(line); // move line into data array (the csvlist) }
private void process_line(String x) { int q2pos; string thename; String[] ints; q2pos = …. // skip the initial quote sign thename = x.Substring(1, q2pos); ints = x.Substring(q2pos+3).Split(','); csvlist.Add(new csvrow() { name = thename, int1 = ints[0], int2 = ints[1], int3=ints[2] }); MessageBox.Show("name="+csvlist[0].name); // prove we got the name }