title: Bind textbox value to datagrid according to selected value in combobox
body: <p>I'm very new to WPF, and I have no idea how to solve the problem.<br>
  I have following DataGrid:        </p>
  
  <pre><code> &lt;DataGrid x:Name="testDataGrid" Grid.Row="1"
                CanUserAddRows="True" CanUserReorderColumns="False" CanUserResizeRows="False" CanUserSortColumns="True"
                AutoGenerateColumns="False" 
                HorizontalAlignment="Left" VerticalAlignment="Top"&gt;
          &lt;DataGrid.Columns&gt;
              &lt;DataGridTextColumn Binding="{Binding SomeString}" Header="SomeString"/&gt;
              &lt;DataGridTextColumn Binding="{Binding quantity, ConverterCulture='de-DE', StringFormat={}{0:N3}}" Header="Quantity"&gt;
                  &lt;DataGridTextColumn.ElementStyle&gt;
                      &lt;Style TargetType="{x:Type TextBlock}"&gt;
                          &lt;Setter Property="HorizontalAlignment" Value="Right"/&gt;
                      &lt;/Style&gt;
                  &lt;/DataGridTextColumn.ElementStyle&gt;
              &lt;/DataGridTextColumn&gt;
              &lt;DataGridTextColumn Binding="{Binding Unit}" Header="Unit"/&gt;
              &lt;DataGridTextColumn Binding="{Binding shortText}" Header="ShortText"/&gt;
              &lt;DataGridTextColumn Binding="{Binding PositionKind}" Header="PositionKind"/&gt;
          &lt;/DataGrid.Columns&gt;
  
          &lt;DataGrid.RowDetailsTemplate&gt;
              &lt;DataTemplate&gt;
                  &lt;Grid&gt;
                      &lt;DataGrid CanUserAddRows="True" CanUserReorderColumns="False" CanUserResizeRows="False" CanUserSortColumns="True"
                                AutoGenerateColumns="False"
                                ItemsSource="{Binding Document}"
                                ScrollViewer.CanContentScroll="True"
                                ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.HorizontalScrollBarVisibility="Auto"
                                MaxHeight="300" MaxWidth="{Binding ElementName=DocumentDataGrid, Path=ActualWidth}"
                                MouseDoubleClick="DataGrid_MouseDoubleClick"&gt;
  
                          &lt;DataGrid.Columns&gt;
                              &lt;DataGridTextColumn Binding="{Binding FNr}" Header="FNr"/&gt;
                              &lt;DataGridTextColumn Binding="{Binding KZ}" Header="KZ"/&gt;
                              &lt;DataGridTextColumn Binding="{Binding Minus}" Header="Minus"/&gt;
                              &lt;DataGridTextColumn Binding="{Binding Factor}" Header="Factor"/&gt;
                              &lt;DataGridTextColumn Binding="{Binding R1}" Header="R1"/&gt;
                              &lt;DataGridTextColumn Binding="{Binding Value1}" Header="Value1"/&gt;
                              &lt;DataGridTextColumn Binding="{Binding R2}" Header="R2"/&gt;
                              &lt;DataGridTextColumn Binding="{Binding Value2}" Header="Value2"/&gt;
                              &lt;DataGridTextColumn Binding="{Binding R3}" Header="R3"/&gt;
                              &lt;DataGridTextColumn Binding="{Binding Value3}" Header="Value3"/&gt;
                              &lt;DataGridTextColumn Binding="{Binding R4}" Header="R4"/&gt;
                              &lt;DataGridTextColumn Binding="{Binding Value4}" Header="Value4"/&gt;
                              &lt;DataGridTextColumn Binding="{Binding R5}" Header="R5"/&gt;
                              &lt;DataGridTextColumn Binding="{Binding Value5}" Header="Value5"/&gt;
                              &lt;DataGridTextColumn Header="Result"/&gt;
                          &lt;/DataGrid.Columns&gt;
                      &lt;/DataGrid&gt;
                  &lt;/Grid&gt;
              &lt;/DataTemplate&gt;
          &lt;/DataGrid.RowDetailsTemplate&gt;
      &lt;/DataGrid&gt;
  </code></pre>
  
  <p>I have a window, which opens by double clicking on the each row of the DataGrid with the following combobox in it:        </p>
  
  <pre><code> &lt;ComboBox x:Name="ComboBoxFormulas" SelectionChanged="ComboBoxFormulas_SelectionChanged" RenderTransformOrigin="0.333,-5.696" Grid.Column="1" Grid.Row="1" Margin="0,0,-190,0"&gt;
              &lt;ComboBoxItem x:Name="oneD"&gt;SomeItem1&lt;/ComboBoxItem&gt;
              &lt;ComboBoxItem x:Name="oneP"&gt;SomeItem2&lt;/ComboBoxItem&gt; 
  </code></pre>
  
  <p>Depending on selected ComboBoxItem different textLabels and textBoxes become visible:         </p>
  
  <pre><code>&lt;TextBox x:Name="txtBox1" Grid.Column="0" Grid.Row="1"  PreviewTextInput="TextBox_PreviewTextInput_Numeric" Grid.ColumnSpan="2"&gt;
              &lt;TextBox.Style&gt;
                  &lt;Style TargetType="TextBox"&gt;
                      &lt;!--by default elements for formula input are invisible--&gt;
                      &lt;Setter Property="Visibility" Value="Collapsed" /&gt;
                      &lt;Style.Triggers&gt;
                          &lt;!--show elements only when needed--&gt;
                          &lt;DataTrigger Binding="{Binding ElementName=oneD, Path=IsSelected}" Value="True"&gt;
                              &lt;Setter Property="Visibility" Value="Visible"/&gt;
  </code></pre>
  
  <p>So what happens is: user double clicks on a row in datagrid and a new window appers. He can input values in textBoxes depending on selected comboBoxItem, then he clicks Enter and these values have to appear in the DataGrid. Could you please help me? I'm really stuck and I don't even know where to start. Any help and suggestions would be greatly appreciated.<br>
  edit1: The code behind the Window I'm talking about is something like this:    </p>
  
  <pre><code>public partial class FormelAssistent : Window
  {
      //public ObservableCollection&lt;LPosition&gt; OZList { get; set; }
      //LPosition Oz = new LPosition();
  
      public FormelAssistent()
      {
          InitializeComponent();
          //this.DataContext = new { OZList = OZList };
          //OZs.ItemsSource = OZList;
          //this.OZList = new ObservableCollection&lt;LPosition&gt;();
          //this.OZList.Add(Oz);
      }
  
  
      //switch between labels according to selected formulas
      private void ComboBoxFormulas_SelectionChanged(object sender, SelectionChangedEventArgs e)
      {
          ComboBox comboBox = sender as ComboBox;
          ComboBoxItem item = comboBox.SelectedItem as ComboBoxItem;
          string content = item.Content.ToString();
  
          Image img = new Image();
          switch (content)
          {
              case "Formel01 - Dreieck":
                  img.Source = new BitmapImage(new Uri("/Im/Formel01_Dreieck.jpg", UriKind.Relative));
                  break;
              case "Formel01 - Prisma":
                  img.Source = new BitmapImage(new Uri("/Im/Formel01_Prisma.jpg", UriKind.Relative));
                  break;
              case "Formel02 - Dreieck":
                  img.Source = new BitmapImage(new Uri("/Im/Formel02_Dreieck.jpg", UriKind.Relative));
                  break; 
  </code></pre>
  
  <p>...</p>
  
  <p>It does nothing special related to my question. It changes the images depending on comboBoxItems selected.
  edit2: The DataGrid where the new rows read from the Window textboxes looks like this:<a href="http://i.imgur.com/cznnOSj.jpg" rel="nofollow">DataGrid</a></p>