title: dynamically adding/removing rows & controls in grid in silverlight
body: <p>I am trying to create a rule screen where user can specify different rules, save them &amp; later on apply on data. User can also group the rules for AND OR condition. My query is if this is the right way to do it &amp; when user clicks on remove that row should be removed, I am not sure how to do that?</p>
  
  <p>Following is my XAML : </p>
  
  <pre><code>&lt;Grid x:Name="LayoutRoot" Background="White" Width="600" Height="200" ShowGridLines="True"&gt;
      &lt;Grid.RowDefinitions&gt;&lt;RowDefinition Height="30" /&gt;&lt;/Grid.RowDefinitions&gt;
      &lt;Grid.ColumnDefinitions&gt;&lt;ColumnDefinition Width="135"/&gt;&lt;ColumnDefinition Width="25"/&gt;&lt;ColumnDefinition Width="135"/&gt;&lt;ColumnDefinition Width="135"/&gt;
          &lt;ColumnDefinition Width="135"/&gt;&lt;ColumnDefinition Width="*"/&gt;
      &lt;/Grid.ColumnDefinitions&gt;
      &lt;telerik:RadComboBox Name="Header" Grid.Row="0" Width="100" HorizontalAlignment="Left"&gt;
              &lt;telerik:RadComboBoxItem Content="And" IsSelected="True"&gt;&lt;/telerik:RadComboBoxItem&gt;
              &lt;telerik:RadComboBoxItem Content="Or"&gt;&lt;/telerik:RadComboBoxItem&gt;
          &lt;/telerik:RadComboBox&gt;
      &lt;telerik:RadButton Content="+" Height="31" HorizontalAlignment="Left" Margin="106,0,0,0" Name="btnAdd" VerticalAlignment="Top" Width="26" Click="btnAdd_Click" /&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p>And code behind is: </p>
  
  <pre><code>   private void btnAdd_Click(object sender, RoutedEventArgs e)
      {
          var row = new RowDefinition();
  
          row.Height = new GridLength(30);
          LayoutRoot.RowDefinitions.Add(row);
  
          var columnCombo = new Telerik.Windows.Controls.RadComboBox() { Width = 100, Height = 30, HorizontalAlignment = HorizontalAlignment.Left };
          columnCombo.Items.Add("Column1");
          columnCombo.Items.Add("Column2");
          columnCombo.Items.Add("Column3");
  
          var operatorCombo = new Telerik.Windows.Controls.RadComboBox() { Width = 100, Height = 30, HorizontalAlignment = HorizontalAlignment.Left};
          operatorCombo.Items.Add("contains");
          operatorCombo.Items.Add("startsWith");
          operatorCombo.Items.Add("endsWith");
  
          var btnRemove = new Telerik.Windows.Controls.RadButton() { Width = 20, Height = 30, Content = "X" };
          btnRemove.Click += new RoutedEventHandler(btnRemove_Click);
  
          var btnGroup = new Telerik.Windows.Controls.RadButton() { Content = "Group", Width = 50, Height = 30 };
          btnGroup.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
          btnGroup.Click += new RoutedEventHandler(btnGroup_Click);
  
          var calendar = new Telerik.Windows.Controls.RadDatePicker();
  
          LayoutRoot.Children.Add(btnRemove);
          LayoutRoot.Children.Add(btnGroup);
          LayoutRoot.Children.Add(columnCombo);
          LayoutRoot.Children.Add(operatorCombo);
          LayoutRoot.Children.Add(calendar);
  
          int newrow = LayoutRoot.RowDefinitions.Count-1;
  
          Grid.SetRow(btnRemove, newrow);
          Grid.SetColumn(btnRemove, 1);
          Grid.SetRow(columnCombo, newrow);
          Grid.SetColumn(columnCombo, 2);
          Grid.SetRow(operatorCombo, newrow);
          Grid.SetColumn(operatorCombo, 3);
          Grid.SetRow(calendar, newrow);
          Grid.SetColumn(calendar, 4);
          Grid.SetRow(btnGroup, newrow);
          Grid.SetColumn(btnGroup, 5);
  
      }
  
      public void btnGroup_Click(object sender, RoutedEventArgs e)
      {
          throw new NotImplementedException();
      }
  
      public void btnRemove_Click(object sender, RoutedEventArgs e)
      {
  
          //TODO: Here I want to find out from which Gridrow user has clicked &amp; remove that grid row &amp; controls inside it.
      }
  </code></pre>