Welcome to the Xceed Community | Help
Community Search  

Does version 3.0 supports ObservableCollection for editing and adding new record?

Sort Posts: Previous Next
  •  08-18-2008, 1:45 PM Post no. 14135

    Does version 3.0 supports ObservableCollection for editing and adding new record?

    Does version 3.0 supports ObservableCollection for editing and adding new record? Or we still have to use IBindingList Interface.

    If yes can you guide me with any examples.

    Thanks

     Atul 

     

  •  08-18-2008, 2:06 PM Post no. 14136 in reply to 14135

    Re: Does version 3.0 supports ObservableCollection for editing and adding new record?

    Version 3.0 supports insertion and editing in almost any data source with or without IBindingList. For example, the following code demonstrates how to bind the grid, through a DataGridCollectionViewSource, to an ObservableCollection of "Person" objects. The InsertionRow added to the FixedHeaders allows new items to be added to the collection.

       <Grid xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid">

          <Grid.Resources>

             <xcdg:DataGridCollectionViewSource x:Key="cvs_persons"

                                                Source="{Binding Path=PersonsCollection}"/>

          </Grid.Resources>

          <xcdg:DataGridControl x:Name="PersonsGrid"

                                ItemsSource="{Binding Source={StaticResource cvs_persons}}">

             <xcdg:DataGridControl.View>

                <xcdg:TableView>

                   <xcdg:TableView.FixedHeaders>

                      <DataTemplate>

                         <xcdg:InsertionRow/>

                      </DataTemplate>

                   </xcdg:TableView.FixedHeaders>

                </xcdg:TableView>

             </xcdg:DataGridControl.View>

          </xcdg:DataGridControl>

       </Grid> 

    If you want to manually handle how items are inserted, you can handle the insertion events exposed by the DataGridCollectionView[Source] classes. See Inserting Data (http://doc.xceedsoft.com/products/XceedWpfDataGrid/Inserting_Data.html) in the documentation.


    Technical Writer - Xceed Software

    In three words I can sum up everything I've learned about life: it goes on.
  •  08-18-2008, 2:25 PM Post no. 14138 in reply to 14136

    Re: Does version 3.0 supports ObservableCollection for editing and adding new record?

    Thanks for the reply. Actually in version 2.0 I was not able to insert records as exception would be thrown where it complains that cannot insert as the datasource is not a proper one.

     After doing much research it turns out that I need to implement IBindingList interface to support that.

     Anyway I found the link on the version 3.0 where "Example 1: Manually handling the insertion process"

     

  •  08-18-2008, 4:20 PM Post no. 14156 in reply to 14136

    Re: Does version 3.0 supports ObservableCollection for editing and adding new record?

    Based on version 3.0 when I am implementing insert I am getting exception "When manually handling the item-insertion process the CreatingNewItem, CommittingNewItem, and CancelingNewItem events must all be handled."

     Even though I am implementing all the events mentioned in the example and have also paced them in XAML

     <xcdg:DataGridCollectionViewSource x:Key="cvs_persons"
                                           
    Source="{Binding Source={x:Static Application.Current},
                                                            
    Path=PersonList}"
                                           
    CreatingNewItem="CollectionView_CreatingNewItem"
                                           
    CommittingNewItem="CollectionView_CommittingNewItem"
                                           
    CancelingNewItem="CollectionView_CancelingNewItem"/

    C# Copy Code

    private void CollectionView_CreatingNewItem( object sender, DataGridCreatingNewItemEventArgs e )
    {
     e.NewItem =
    new Person( Person.AutoIncrementID, string.Empty, string.Empty, -1 );
     e.Handled = true;
    }
    private void CollectionView_CommittingNewItem( object sender, DataGridCommittingNewItemEventArgs e )
    {
     List<Person> source = e.CollectionView.SourceCollection
    as List<Person>;
     source.Add( ( Person )e.Item );
     Person.AutoIncrementID = Person.AutoIncrementID + 1;
     
    // the new item is always added at the end of the list.     
     
    e.Index = source.Count - 1;
     e.NewCount = source.Count;
     e.Handled = true;
    }
    private void CollectionView_CancelingNewItem( object sender, DataGridItemHandledEventArgs e )
    {
     
    // Manually handling the insertion of new items requires that the CreatingNewItem,
     
    // CommitingNewItem, and CancelingNewItem events must all be handled even if nothing
     
    // is done in the event.
     
    e.Handled = true;
    }

     What could be wrong?

     

     

     

  •  08-18-2008, 4:24 PM Post no. 14158 in reply to 14156

    Re: Does version 3.0 supports ObservableCollection for editing and adding new record?

    The code you provided is from the documentation. I assume that you have set e.Handled to true in all 3 event handlers as well?
    Technical Writer - Xceed Software

    In three words I can sum up everything I've learned about life: it goes on.
  •  08-18-2008, 5:52 PM Post no. 14168 in reply to 14158

    Re: Does version 3.0 supports ObservableCollection for editing and adding new record?

    Thanks for your prompt reply. Yes I found the bug and I was missing one of the e.Handled = true; statement.

    I am good for now.

    Thanks 

     

View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2008 Xceed Software Inc.