title: Populate a DataGrid using ViewModel via a database
body: <p>Basically, I have a 4 files that I'm dealing with:</p>
  
  <p><code>DBDisplay.xaml</code></p>
  
  <p><code>DBDisplay.xaml.cs</code></p>
  
  <p><code>DBDisplayViewModel.cs</code></p>
  
  <p><code>DBConn.cs</code></p>
  
  <p>In my ViewModel I am trying to populate the following DataGrid from my .xaml file:</p>
  
  <pre><code>&lt;DataGrid ItemsSource="{Binding Path=Users}"/&gt;
  </code></pre>
  
  <p>With the following code:</p>
  
  <pre><code>public class DBDisplayViewModel
  {
      public ICollectionView Users { get; set; }
  
      DBConn dbCon;   // the connection object
      DataSet dataSet;
      DataRow dataRow;
  
      private void Load()
      {
          string connectionString = Properties.Settings.Default.UserDB;
  
          dbCon = new DBConn(connectionString);
  
          dbCon.openConnection();
  
          dataSet = dbCon.getDataSet(Queries.SelectAll);
  
          DataTable table = dataSet.Tables[0];
          PopulateTextFields(table, 1);
  
          //Something to go here to populate the DataGrid
  
      }
  
      private void PopulateTextFields(DataTable table, int i)
      {
          dataRow = table.Rows[i];
  
      }
  
     public DBDisplayViewModel()
     {
  
         Load();
  
         Users = CollectionViewSource.GetDefaultView(SOMETHING_HERE);
     }
  
      private void Closed(object sender, EventArgs e)
      {
          dbCon.closeConnection();
      }
  
  }
  </code></pre>
  
  <p>So <code>SOMETHING_HERE</code> should be linking to my database (as this is how I connected to a list of users before)
  Also I'm thinking I need something like </p>
  
  <pre><code>DataGrid.DataSource = table;  //DataGrid would be linking to the xaml code
  </code></pre>
  
  <p>To populate the DataGrid</p>
  
  <p>I'm at and ends here, so if anyone can help, I'd be very happy!</p>