0

I am using a DataGrid to present data from a List<VideoFile> containing objects with mostly string properties describing a video file like title, runtime, quality etc. I want to be able to arrange and edit displayed data via the DataGrid and refresh DataGrid content on the fly. I'm new to WPF so i've read multiple threads on the topic and i am pretty confused what is the best (least complex, fastest) way to achieve this.

My current implementation:

GlobalVariables.List1 = Program.LoadFromXML(GlobalVariables.DatabaseLocation);
GlobalVariables.itemCollectionViewSource = (CollectionViewSource)(FindResource("ItemCollectionViewSource"));
GlobalVariables.itemCollectionViewSource.Source = GlobalVariables.List1;

XAML:

<Window.Resources>
    <CollectionViewSource 
        x:Key="ItemCollectionViewSource"  
        CollectionViewType="ListCollectionView"/>
</Window.Resources>


<DataGrid x:Name="LibraryDisplay"
          Margin="10,10,10,0"
          Height="527" Width="715" 
          ItemsSource="{Binding}"
          DataContext="{StaticResource ItemCollectionViewSource}"       
          AutoGenerateColumns="True"
          HorizontalAlignment="Left" 
          VerticalAlignment="Top" 
          IsReadOnly="False" 
          SelectionChanged="DataGrid_SelectionChanged" 
          CellEditEnding="DataGrid_CellEditEnding" 
         />

AutoGenerateColums is set temporarily. Here is a part of how it looks:

DataGrid look

illid44n
  • 57
  • 2
  • 5
  • You can try to use ObservableCollection as source to your CollectionViewSource. I am sure about your datasource from the above code. – Ayyappan Subramanian Feb 04 '15 at 15:28
  • Try the following link: http://stackoverflow.com/questions/23081088/wpf-datagrid-filtering-refreshing-collectionviewsource-refreshing Or http://stackoverflow.com/questions/12034840/handling-onpropertychanged – Telimaktar Feb 04 '15 at 15:33
  • @Telimaktar Thx the links u posted solved my case though i wasnt certain if CollectionViewSource is the right path to follow and so i asked the question. – illid44n Feb 04 '15 at 21:31

0 Answers0