title: How to clear datagrid items in wpf while having button in column of each row
body: <p>I want to delete datagrid items in wpf.</p>
  
  <p>I have tried </p>
  
  <pre><code> dataGridfix.Items.Clear();
   dataGridfix.Items.Refresh();
   dataGridfix.ItemsSource = null;
  </code></pre>
  
  <p>but due to having button in each row , it stops to clear datagrid.</p>
  
  <p>can u suggest good idea?</p>
  
  <p>full code is here </p>
  
  <pre><code>   private void showfix() 
     {
           dataGridfix.ItemsSource = null;
           DataTable dt = new DataTable();
           dt.Columns.Add("ID");
           dt.Columns.Add("Account");
  
           SqlDataAdapter msadapt = new SqlDataAdapter("select * from fdetails  order by fdid desc", mscon);
           DataTable msdata = new DataTable();
           msadapt.Fill(msdata);
  
           for (int i = 0; i &lt; msdata.Rows.Count; i++) 
           {
               string id = msdata.Rows[i].ItemArray[0].ToString();
               string acc = msdata.Rows[i].ItemArray[2].ToString();
               dt.Rows.Add(id, acc);
           }
  
           dataGridfix.ItemsSource = dt.DefaultView;
           dataGridfix.Columns[0].Width = 50;
           dataGridfix.Columns[1].Width = 50;
           dataGridfix.Columns[2].Width = 180;
       }
  </code></pre>
  
  <p>xaml code is</p>
  
  <pre><code>                                &lt;DataGridTemplateColumn &gt;
                                      &lt;DataGridTemplateColumn.CellTemplate &gt;
                                          &lt;DataTemplate&gt;
                                              &lt;Button Name="btndelfix" Click="btndelfix_Click" &gt;Delete&lt;/Button&gt;
                                          &lt;/DataTemplate&gt;
                                      &lt;/DataGridTemplateColumn.CellTemplate&gt;
                                  &lt;/DataGridTemplateColumn&gt;
                              &lt;/DataGrid.Columns&gt;
  </code></pre>