title: Binding data in WPF
body: <p>I'm trying to make simple WPF app with c# and I have following problem:
  in my app I'm using class "Macierz" to represent and work with array of BigInteger objects. Now I need to graphically represent this array, using DataGrid (or something different if there is a better way to do this) and I have no idea how can I bound this DataGrid to my class. I had tried to do this by Data Sources window (VS 2013) but when I added my class to it my array didn't display.
  Here is some code of my class:</p>
  
  <pre><code>public class Macierz
  {
      public Macierz(ulong A, ulong B)
      {
          a = A;
          b = B;
          M = new BigInteger[A, B];
      }
  
  
      private ulong a, b;
      public ulong A
      {
          get
          {
              return a;
          }
      }
  
      public ulong B
      {
          get
          {
              return b;
          }
      }
  
      private BigInteger[,] M;
  
      public BigInteger this[ulong A, ulong B]
      {
          get
          {
              return M[A, B];
          }
          set
          {
              M[A, B] = value;
          }
      }
  </code></pre>
  
  <p>I need to represent in array with cells of textBoxes or something like that, so a user can easily change value of specific cell.</p>
  
  <p>Edit:
  Now, thanks to user3148019 answer I added this method in my class:</p>
  
  <pre><code> public DataTable ToDataTable()
      {
          DataTable table = new DataTable();
          DataRow tmp;
          for (ulong i = 0; i &lt; b; i++)
              table.Columns.Add(i.ToString(), typeof(BigInteger));
  
          for (ulong i = 0; i &lt; a; i++)
          {
              tmp = table.NewRow();
              for (ulong j = 0; j &lt; b; j++)
                  tmp[j.ToString()] = M[i, j];
  
              table.Rows.Add(tmp);
          }
          return table;
      }
  </code></pre>
  
  <p>so now I can show my array using DataGrid but this requires twice more memory and user can't change any values in original array. I tried to change my class replacing simple BigInteger[a, b] array with DataTable object but I have problem with accessing specific cells. For example:</p>
  
  <pre><code>public BigInteger tmp = 0;
  for (ulong i = 0; i &lt; a; i++)
  
              for (ulong j = 0; j &lt; b; j++)
              {
                  tmp += table.Rows[i].ItemArray[j];
              }
  </code></pre>
  
  <p>This generate errors:</p>
  
  <blockquote>
    <p>Error 1   The best overloaded method match for 'System.Data.DataRowCollection.this[int]' has some invalid arguments<br>
    Error  2   Argument 1: cannot convert from 'ulong' to 'int'</p>
  </blockquote>
  
  <p>Is number of rows and columns in DataTable object limited to max of int or there is another way to access DataTable members?</p>
  
  <p>Edit2:<br>
  I should say it earlier, that Macierz will never change any value inside array, so only user can change values of cell witch means I don't need INotifyCollectionChange (or maybe am I wrong?). Also now I think that showing full array is not always necessary. I don't want Macierz to derive from DependencyObject because I want to use it in other console application. I want to achieve my goal in simplest way. This is what I have now in Macierz:</p>
  
  <pre><code> public DataTable ToDataTable(ulong AStart, ulong ACount, ulong BStart, ulong BCount)
      {
          if (AStart &gt;= a)
              AStart = a - 1;
          if (BStart &gt;= b)
              BStart = b - 1;
  
          ulong AStop = AStart + ACount;
          ulong BStop = BStart + BCount;
  
          if (AStop &gt; a)
              AStop = a;
          if (BStop &gt; b)
              BStop = b;
  
          DataTable table = new DataTable();
          DataRow tmp;
          BigInteger BItmp;
  
          for (ulong i = BStart; i &lt; BStop; i++)
              table.Columns.Add(i.ToString(), typeof(BigInteger));
          table.Columns.Add("Suma", typeof(BigInteger));
  
          for (ulong i = AStart; i &lt; AStop; i++)
          {
              tmp = table.NewRow();
              for (ulong j = BStart; j &lt; BStop; j++)
                  tmp[j.ToString()] = M[i, j];
  
              BItmp = 0;
              for (ulong j = 0; j &lt; B; j++)
                  BItmp += M[i, j];
              tmp["Suma"] = BItmp; 
  
              table.Rows.Add(tmp);
          }
          return table;
      }
  </code></pre>
  
  <p>and in MainWindow.xaml.cs:</p>
  
  <pre><code>private void PokazButton_Click(object sender, RoutedEventArgs e)
      {
          this.Cursor = Cursors.Wait;
  
          if (czyCala.IsChecked == true)
              GridTabela = M.ToDataTable(0, M.A, 0, M.B);
          else
              GridTabela = M.ToDataTable(VA, VACount, VB, VBCount);
  
          TabelaDataGrid.DataContext = this;
          TabelaDataGrid.ItemsSource = GridTabela.DefaultView;
  
          this.Cursor = null;
      }
  </code></pre>
  
  <p>This is working very well, allowing me to display array to user in easy way, but I don't now how to allow user change values in original array. I was trying to use CellEditEnding DataGrid event but I don't now how to access, read and validate input made by user in specific cell, especially how to get coordinates of that cell (I should probably get this information somehow like this "e.Column.something" or "e.Row.something" but I can't figure out how to do this).</p>