title: If-statement inside Add() method?
body: <p>I'm trying to add each line of a textfile to different columns in a <code>listView</code>. However, I've run into a problem. </p>
  
  <p>This is how I did a method:</p>
  
  <pre><code>public void OpenFile()
          {
              OpenFileDialog openFileDialog = new OpenFileDialog();
              openFileDialog.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*";
              string line = "";
              int index = 0;
              if (openFileDialog.ShowDialog() == true)
              using (StreamReader sr = File.OpenText(openFileDialog.FileName))
              {
                  while ((line = sr.ReadLine()) != null)
                  {
                      index++;
                      if (index == 1)
                          InvoiceNumbertxt.Text = line;
                      else if (index == 2)
                          InvoiceDatetxt.Text = line;
                      else if (index == 3)
                          DueDatetxt.Text = line;
                      else if (index == 4 || index == 5 || index == 6 || index == 7 || index == 8 || index == 9)
                          PersonInfolst.Items.Add(line);
                      else if (index == 10)
                      {
                          Items.Add(new ItemProperties 
                          {     
                              Item = line
                              if(index == 11)// &lt;---- If-statement inside Add?
                              Description = line;
  
  
                          });
                          itemlst.ItemsSource = Items;
                      }
                      else
                          break;
                  }
              }
          }
  </code></pre>
  
  <p>As you can see index is just a convenient flag (variable) to insert the lines in order, and not overlap multiple lines into the same control.</p>
  
  <p><strong>The problem</strong> I have is I want to check if index is a value <em>inside</em> the Add() method so that I can add the new textFile line to the same row but different column in the list. </p>
  
  <p><strong>UPDATE:</strong></p>
  
  <pre><code>public partial class MainWindow : Window
      {
          ObservableCollection&lt;ItemProperties&gt; Items =
          new ObservableCollection&lt;ItemProperties&gt;();
          public MainWindow()
          {
              InitializeComponent();
          }
          public ObservableCollection&lt;ItemProperties&gt; GameCollection
          {
              get
              {
                  if (Items == null)
                  {
                      Items = new ObservableCollection&lt;ItemProperties&gt;();
                  }
                  return Items;
              }
          } 
  
          private void btnOpenFile_Click(object sender, RoutedEventArgs e)
          {
              OpenFile();
          }
  
          public void OpenFile()
          {
              OpenFileDialog openFileDialog = new OpenFileDialog();
              openFileDialog.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*";
              string line = "";
              int index = 0;
              if (openFileDialog.ShowDialog() == true)
              using (StreamReader sr = File.OpenText(openFileDialog.FileName))
              {
                  while ((line = sr.ReadLine()) != null)
                  {
                      index++;
                      if (index == 1)
                          InvoiceNumbertxt.Text = line;
                      else if (index == 2)
                          InvoiceDatetxt.Text = line;
                      else if (index == 3)
                          DueDatetxt.Text = line;
                      else if (index == 4 || index == 5 || index == 6 || index == 7 || index == 8 || index == 9)
                          PersonInfolst.Items.Add(line);
                      else if (index == 10)
                      {
                          Items.Add(new ItemProperties { Item = line });
                          itemlst.ItemsSource = Items;
                      }
                      else if (index == 11)
                      {
                          //??
  
                      }
                      else
                          break;
                  }
              }
          }
  
          private void btnOpenImage_Click(object sender, System.Windows.RoutedEventArgs e)
          {
              Microsoft.Win32.OpenFileDialog openfile = new Microsoft.Win32.OpenFileDialog();
              openfile.DefaultExt = "*.jpg";
              openfile.Filter = "Image Files|*.jpg";
              Nullable&lt;bool&gt; result = openfile.ShowDialog();
              if (result == true)
              {
                  imagefile.Source = new BitmapImage(new Uri(openfile.FileName));
              }
          }
  
          public class ItemProperties
          {
              public string Item { get; set; }
              public string Description { get; set; }
              public string Quantity { get; set; }
              public string UnitPrice { get; set; }
              public string Tax { get; set; }
          }
      }
  </code></pre>