title: Data binding Datagrid WPF
body: <p>I have created a datagrid with each object has their own line. I added two column (edit,remove) but the command won't execute. I am using MVVM pattern. Here is the datagrid</p>
  
  <pre><code>&lt;DataGrid Name="dgBillMeta" ItemsSource="{Binding FileObjectCollection}" AutoGenerateColumns="False" Grid.Row="0" IsReadOnly="False" &gt;
                  &lt;DataGrid.Columns&gt;
                      &lt;DataGridTextColumn Header="ID"  Binding="{Binding id}"&gt;&lt;/DataGridTextColumn&gt;
                      &lt;DataGridTextColumn Header="Name" Binding="{Binding attName}"&gt;&lt;/DataGridTextColumn&gt;
                      &lt;DataGridCheckBoxColumn Header="Key" Binding="{Binding isKey}"&gt;&lt;/DataGridCheckBoxColumn&gt;
                      &lt;DataGridTextColumn Header="Type" Binding="{Binding attType}"&gt;&lt;/DataGridTextColumn&gt;
                      &lt;DataGridTextColumn Header="Required" Binding="{Binding isRequired}"&gt;&lt;/DataGridTextColumn&gt;
                      &lt;DataGridTextColumn Header="Location" Binding="{Binding attLoc}"&gt;&lt;/DataGridTextColumn&gt;
                      &lt;DataGridTextColumn Header="Length" Binding="{Binding attLength}"&gt;&lt;/DataGridTextColumn&gt;
                      &lt;DataGridTextColumn Header="Decimal" Binding="{Binding isDecimal}"&gt;&lt;/DataGridTextColumn&gt;
                      &lt;DataGridTextColumn Header="Alignment" Binding="{Binding attAlignment}"&gt;&lt;/DataGridTextColumn&gt;
                      &lt;DataGridTemplateColumn&gt;
                          &lt;DataGridTemplateColumn.CellTemplate&gt;
                              &lt;DataTemplate&gt;
                                  &lt;Button Content="Edit"&gt;&lt;/Button&gt;                                
                              &lt;/DataTemplate&gt;
                          &lt;/DataGridTemplateColumn.CellTemplate&gt;
                      &lt;/DataGridTemplateColumn&gt;
  
                      &lt;DataGridTemplateColumn Header="delete"&gt;
                          &lt;DataGridTemplateColumn.CellTemplate&gt;
                              &lt;DataTemplate&gt;
                                  &lt;Button Command="{Binding remCommand}" Content="Remove"/&gt;
                              &lt;/DataTemplate&gt;
                          &lt;/DataGridTemplateColumn.CellTemplate&gt;
                      &lt;/DataGridTemplateColumn&gt;
                  &lt;/DataGrid.Columns&gt;
              &lt;/DataGrid&gt;
  </code></pre>
  
  <p>I can see edit, and remove but when clicking on it, the object does not execute from my ModelView. If I put the button outside the datagrid ( anywhere on the windows, it does work).</p>
  
  <p>Here how the ViewModel works</p>
  
  <pre><code>   internal class BillMetaDataViewModel
      {
          private ObservableCollection&lt;BillMetaData&gt; _MyDataList;
          private Command removeCommand;
  
          public BillMetaDataViewModel()
          {
              Database dbobj = new Database();
              MongoDatabase dtbase = dbobj.getDatabase;
              var collection = dtbase.GetCollection&lt;BillMetaData&gt;("BillMetaData");
              var entity = collection.FindAll();
              _MyDataList = new ObservableCollection&lt;BillMetaData&gt;(entity.ToList());
              removeCommand = new Command(removeComm);
          }
  
          public ObservableCollection&lt;BillMetaData&gt; FileObjectCollection
          {
              get { return _MyDataList; }
          }
  
          public void removeComm()
          {
              MessageBox.Show("Hello MessageBox"); 
          }
  
          public Command remCommand
          {
              get { return removeCommand; }
          }
      }
  </code></pre>
  
  <p>I may be missing selection number, but i am trying to learn first I believe it has to do something with the path but i am not sure how it would work. I have defined my datacontext on the xaml as follow</p>
  
  <pre><code>InitializeComponent();
  DataContext = new BillMetaDataViewModel();
  </code></pre>