Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

WPF code question. I was wondering why this should be a private void class and the logic of the while loop. ----------------- { /// ///

WPF code question.

I was wondering why this should be a "private void" class and the logic of the while loop.

-----------------

{ ///  /// Interaction logic for MainWindow.xaml ///  public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } private void Window_Loaded(object sender, RoutedEventArgs e) { FileStream fs = null; StreamReader sr = null; try { fs = new FileStream(@"..\..\..\deltagerliste.csv", FileMode.Open, FileAccess.Read); sr = new StreamReader(fs, Encoding.Default); string str; string[] tokens; char[] separators = { ',' }; // str.split needs a char array List lines = new List(); string nextLine = ""; str = sr.ReadLine(); // Don't show the first line with headings while (!sr.EndOfStream) { str = sr.ReadLine(); str = str.Replace("\"", string.Empty); if (str != "") { tokens = str.Split(separators, StringSplitOptions.RemoveEmptyEntries); // Build the string to put into the listbox if (tokens[1].Length > 20) tokens[1] = tokens[1].Substring(0, 20); // Limit first name to max 20 chars //nextLine = string.Format("{0,-20} {1,-20} {2,-12} {3,20}", tokens[1], tokens[0], tokens[3], tokens[2]); // Old format nextLine = $"{tokens[1],-20} {tokens[0],-20} {tokens[2],-12}"; lines.Add(nextLine); // You could instead add each line with lbxDeltagere.Items.add //lbxDeltagere.Items.Add(nextLine); } } lbxDeltagere.ItemsSource = lines; // Set the listboxs ItemSource to point to the list of lines } catch (Exception ex) { MessageBox.Show(ex.Message, "An error occured during file IO"); } finally { sr.Close(); fs.Close(); } } } } 

------------------------------------------------------------------------------------------------------------------

Thank you!!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

13-1 How does building new systems produce organizational change?

Answered: 1 week ago