title: How to Remove the Last Row in Grid using WPF?
body: <p>I have Two buttons in my Wpf UI named as Add,Remove. My requirement is, if i click add button it has to Add new row with two columns. If i click remove button, it has to remove the Last Inserted Row. I am using Grid for this.
  I want to remove the Last Row from the Grid. I am able to add rows with 2 columns. I have the code for Remove. But it says some error. I donno how to remove the last inserted row entirely if i click Remove button. I have the following code. </p>
  
  <pre><code>public int count = 1;
      private void btn_add_Click(object sender, RoutedEventArgs e)
      {
          //Creating Rows..
          RowDefinition row0 = new RowDefinition();
          row0.Height = new GridLength(30);
          grid1.RowDefinitions.Add(row0);
  
          //Creating columns..
          ColumnDefinition col0 = new ColumnDefinition();
          ColumnDefinition col1 = new ColumnDefinition();
          ColumnDefinition col2 = new ColumnDefinition();
          col0.Width = new GridLength(100);
          col1.Width = new GridLength(100);
  
          grid1.ColumnDefinitions.Add(col0);
          grid1.ColumnDefinitions.Add(col1);
  
  
          int i = count;
          ComboBox cmb = new ComboBox();
          cmb.Items.Add("add");
          cmb.Items.Add("remove");
  
          Grid.SetRow(cmb, i);
          Grid.SetColumn(cmb, 0);
  
          grid1.Children.Add(cmb);
  
          TextBox txt = new TextBox();
          Grid.SetRow(txt, i);
          Grid.SetColumn(txt, 1);
          grid1.Children.Add(txt);
          count++;
      }
  
      private void btn_remove_Click(object sender, RoutedEventArgs e)
      {
          grid1.RowDefinitions.RemoveAt(count);
          count--;
      }
  </code></pre>