Powered by MSDN

US - English
NEW! Silverlight 5 is available Learn More

Dataform requirements for add button RSS

28 replies

Last post Jan 12, 2011 07:08 AM by farris_lime

(0)
  • jps777

    jps777

    Member

    8 Points

    17 Posts

    Dataform requirements for add button

    Apr 27, 2009 08:29 PM | LINK

     What are the requirements (binding etc) for the dataform's add button to be displayed and usable?

  • Luke Longley

    Luke Longley

    Member

    465 Points

    92 Posts

    Re: Dataform requirements for add button

    Apr 27, 2009 11:11 PM | LINK

    There are two, basically: the DataForm's ItemsSource must be set, and the ItemsSource it receives must be capable of having new items added to it (e.g., an IList, or something implementing IEditableCollectionView).

  • jps777

    jps777

    Member

    8 Points

    17 Posts

    Re: Dataform requirements for add button

    Apr 28, 2009 01:38 AM | LINK

     I have a view model which loads organizations into a domain context. Locations and Contacts are eagerly loaded for each organization returned. For each of the three entities (Organization, Location, and Contact) there's a datagrid (master) and dataform (detail). The organizations are returned by the domain service in an EntityList while locations and contacts are returned in EntityCollections. If I set ItemsSource for the organization dataform to the organizations EntityList I get an add button. On the other hand if I set ItemsSource for locations and contacts to their corresponding EntityCollection I don't get an add button. As far as I can tell the form should be able to add to an EntityCollection. What am I doing wrong?

     

    Also, I'd like to use the dataform in each master/detail relationship to disply the currently selected record in the grid and for adding new records. It seems like I can only allow one or the other because to display the record selected in the grid in the dataform I have to bind CurrentItem to the grid's SelectedItem but to allowing adding I have to set the ItemsSource. Is there a way to accomplish both?

  • Fredrik N

    Fredrik N

    Contributor

    5184 Points

    785 Posts

    Re: Re: Dataform requirements for add button

    Apr 28, 2009 07:29 AM | LINK

    @jps777:

    Here is a solution where you can Add a entity, and also update and view an entity from a DataGird (I use Northwind in the example and EF):

    <StackPanel Orientation="Horizontal">

     

    <data:DataGrid x:Name="myGrid" Width="400" ItemsSource="{Binding Data, ElementName=ds1}"/>

     

    <dataControls:DataForm x:Name="myForm" Width="300" ItemsSource="{Binding Data, ElementName=ds1}" CurrentItem="{Binding SelectedItem, ElementName=myGrid, Mode=TwoWay}" />

     

    <ria:DomainDataSource x:Name="ds1" LoadMethodName="LoadCustomers">

    <ria:DomainDataSource.DomainContext>

    <m:DomainService1/>

    </ria:DomainDataSource.DomainContext>

    </ria:DomainDataSource>

    </StackPanel>

    /Fredrik Normén - fredrikn @ twitter
    MVP, ASPInsider, WCF RIA Services Insider
    My Blog
  • Fredrik N

    Fredrik N

    Contributor

    5184 Points

    785 Posts

    Re: Re: Dataform requirements for add button

    Apr 28, 2009 08:21 AM | LINK

    @jps777:

    About the first problem you have about EntityList and EntityCollection. The EntityList implements the IEditableCollection interface, which indicate the DataForm if an item can be added or not. The EntityCollection doesn't implements the IEditableCollection, and the DataForm will not allow you to add an item becasue of that it seems. I don't know if this is a bug or if it should be that way.. but it's kind of strange regarding to me. The CanAddItems property which indicate if an item can be added or not, is private, so it can't be set.

    There is a CanUserAddItems property, but what I can see, it can't be used to specify that an item can be added or not, it will not have any effect. I guess the reason is the private method SetCanAddItems which will set the CanAddItems property based on which interface is used.

    /Fredrik Normén - fredrikn @ twitter
    MVP, ASPInsider, WCF RIA Services Insider
    My Blog
  • jps777

    jps777

    Member

    8 Points

    17 Posts

    Re: Re: Dataform requirements for add button

    Apr 28, 2009 05:02 PM | LINK

     So is there a way to have the domain service return something that does implement IEditableCollection rather than the default EntityCollection?

  • jps777

    jps777

    Member

    8 Points

    17 Posts

    Re: Re: Dataform requirements for add button

    Apr 29, 2009 02:09 AM | LINK

     I've now spent several hours trying to figure out a way to add Location and Contact entities to the EntityCollention instances they are returned in from the domain service. Although entities can be added (and removed) to an EntityCollection manually it requires that I provide buttons for the user to perform these actions instead of using the built-in DataForm controls. I really wish there was a way I could utilize the DataForm's built in functionality...

     Another roadblock I've run into is that even if Locations and Contacts are added via a child window with a DataForm the changes aren't persisted by the domain service when submitchanges is called on the DomainContext. Is there something special that has to be done to have new/changed related entities (in this case Locations and Contacts for an Organization) persisted?

  • moravsky

    moravsky

    Participant

    1184 Points

    218 Posts

    Re: Re: Dataform requirements for add button

    Apr 29, 2009 02:49 AM | LINK

    Do you have Insert and Update methods on the server for all your entities (Organization, Location, Contact)? Does SubmittedChangesEventArgs in your Submitted handler have any errors? If you have server methods for all entities, then RIA services should persist whole graphs, so there is no need to add entities individually.

    --Petr aka pemoravs
  • jps777

    jps777

    Member

    8 Points

    17 Posts

    Re: Re: Dataform requirements for add button

    Apr 29, 2009 08:41 PM | LINK

     

    moravsky

    Do you have Insert and Update methods on the server for all your entities (Organization, Location, Contact)? Does SubmittedChangesEventArgs in your Submitted handler have any errors? If you have server methods for all entities, then RIA services should persist whole graphs, so there is no need to add entities individually.

     Yes I have insert and update methods on the server and yes there are errors reported in the submitted handler....I just can't make heads or tails of them. If you're interested, I put my project here. The database is included in the project and requires sql server 2008 express. The project is very crude as it's only the result of me playing around with ria services to figure out what it's capable of.

  • kuhlmancer

    kuhlmancer

    Member

    2 Points

    3 Posts

    Re: Re: Dataform requirements for add button

    May 15, 2009 06:22 PM | LINK

    Have you had any progress with this?  I'm having the same issue and didn't want to start a new thread.