title: WPF DataGrid Gives ArgumentOutOfRangeException when clicked
body: <p>I am fairly new to WPF and MVVM and a newb in general, so thank you in advance for your patience.</p>
  
  <p>I am using a custom class in my model, and I have an ObservableCollection of that custom object in my viewmodel.  In the class' constructor, I am adding the object to the collection when it is instantiated.  In my view, I am using a DataGrid that is bound to the collection to list all active instances of the class.  I am trying to implement a drag-and-drop from the DataGrid onto a trash can icon that would allow a user to dispose of unneeded instances of the class.</p>
  
  <p>The problem is that when you click anything in the DataGrid, the program immediately crashes with an ArgumentOutOfRange exception - ("The given DisplayIndex is out of range.  DisplayIndex must be greater than or equal to 0 and less than Columns.Count." "Actual value was 0").  DisplayIndex seems to relate to the DataGrid column, so this exception is probably due to the fact that I am not displaying any columns in the traditional sense - in my DataGrid, AutoGenerateColumns is set to False, and I am displaying everything I need to display using a RowDetailsTemplate.  (The reason for this is that the area where I am displaying the DataGrid is narrow, so I need a nested, item-specific grid to represent the item properly.)  The DataGrid displays and syncs with the collection fine, but obviously has some issues.  I have read dozens of links on DataGrid crashes, and haven't found anything involving this exception.</p>
  
  <p>My desired behavior is to pass the custom object represented by the DataGrid item to a target when I drag and drop it.  I don't care which "column" they clicked or anything else - I just need a way to pass either an object reference or a SelectedIndex (the items index in the collection) to a method in the viewmodel.</p>
  
  <p>Thank you in advance for any help!  The offending bit of code (XAML) seems to be:</p>
  
  <pre><code>&lt;ScrollViewer DockPanel.Dock="Bottom" Margin="2" Width="180" ScrollViewer.VerticalScrollBarVisibility="Auto"&gt;
              &lt;DataGrid ItemsSource="{Binding Path=myCollection, Mode=OneWay}" AutoGenerateColumns="False" RowDetailsVisibilityMode="Visible" HeadersVisibility="None"&gt;
                  &lt;DataGrid.RowDetailsTemplate&gt;
                      &lt;DataTemplate DataType="model:myClass"&gt;
                          &lt;Border CornerRadius="10" Background="AliceBlue"&gt;
                              &lt;Grid&gt;
                                  &lt;Grid.ColumnDefinitions&gt;
                                      &lt;ColumnDefinition Width="*" /&gt;
                                      &lt;ColumnDefinition Width="*" /&gt;
                                      &lt;ColumnDefinition Width="50" /&gt;
                                  &lt;/Grid.ColumnDefinitions&gt;
                                  &lt;Grid.RowDefinitions&gt;
                                      &lt;RowDefinition /&gt;
                                      &lt;RowDefinition /&gt;
                                  &lt;/Grid.RowDefinitions&gt;
                                  &lt;TextBlock Grid.Row="0" Grid.Column="0" Text="{Binding MyString1}" FontSize="21" VerticalAlignment="Bottom" /&gt;
                                  &lt;TextBlock Grid.Row="0" Grid.Column="1" Text="{Binding MyCustomProperty, Converter={StaticResource MyIValueConverter}}" VerticalAlignment="Bottom" /&gt;
                                  &lt;TextBlock Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Text="{Binding MyString2}" TextWrapping="Wrap" /&gt;
                                  &lt;Image Source="/Resources/image1.png" Grid.Column="2" Grid.Row="0"&gt;
                                      &lt;Image.DataContext&gt;
                                          &lt;Properties:Resources/&gt;
                                      &lt;/Image.DataContext&gt;
                                  &lt;/Image&gt;
                                  &lt;Image Source="/Resources/image2.png" Grid.Column="2" Grid.Row="1"&gt;
                                      &lt;Image.DataContext&gt;
                                          &lt;Properties:Resources/&gt;
                                      &lt;/Image.DataContext&gt;
                                  &lt;/Image&gt;
                              &lt;/Grid&gt;
                          &lt;/Border&gt;
                      &lt;/DataTemplate&gt;
                  &lt;/DataGrid.RowDetailsTemplate&gt;
              &lt;/DataGrid&gt;
          &lt;/ScrollViewer&gt;
  </code></pre>