Powered by MSDN

US - English
NEW! Silverlight 5 is available Learn More

Questions about DataGrid + DataForm RSS

6 replies

Last post Aug 15, 2009 04:48 AM by narayans

(0)
  • showen

    showen

    0 Points

    4 Posts

    Questions about DataGrid + DataForm

    May 18, 2009 01:07 PM | LINK

    hi, I'm new to silverlight 3, and I have some questions about the datagrid and dataform, hope someone can help me here.

    1) In the sample website, in the datagrid, and for the 3rd sample (master detail). How does dataform and datagrid are synchronized?

    I mean when you select record in one of those, the content changed in another one, I know I can use 'SelectionChanged' and 'CurrentItemChanged' Event to achieve that, but is there any other way to do it?

    2) Right now I'm using WCF to bind the data to DataGrid and DataForm in code, is ther any other way to do it? I saw the sample website used 'DataContext', how does that work, as I saw the 'ItemSource' for both are set to 'Binding'

     3) In Silverlight app, can I update record row by row like what we did in asp.net GridView . If we can do it, how can I implement that with DataGrid or DataForm controls.

    thanks

    datagrid dataform Silvelight 3

  • yifung

    yifung

    Contributor

    3937 Points

    637 Posts

    Microsoft

    Re: Questions about DataGrid + DataForm

    May 18, 2009 06:06 PM | LINK

    DataGrid and DataForm are synchronized through a CollectionView.  What you do is bind the DataGrid and the DataForm to the same CollectionView, and it maintains currency between the 2 controls.  CollectionView takes in an IEnumerable through its constructor so you can use it to wrap any enumeration.  Binding is what you use for DataBinding in Silverlight.  One way to use Binding is to give it a path that's based on the DataContext of the control.  The DataContext is inherited through the visual tree in Silverlight.  I'm not sure what you mean by update row by row.  The DataGrid does support editing so you can edit the rows

    Yifung Lin [MSFT]
  • showen

    showen

    0 Points

    4 Posts

    Re: Questions about DataGrid + DataForm

    May 18, 2009 09:52 PM | LINK

    thanks for your reply, that's very helpful, I will look into that, for CollectionView how does it work with service or wcf, is there any sample code or url I for that ?

    And when I said row by row, I mean update one record then post back to the server, when I update in Silverlight, it seems to be only clientside update, maybe I haven't figure out how to post back to server yet.

    thanks again

  • showen

    showen

    0 Points

    4 Posts

    Re: Questions about DataGrid + DataForm

    May 19, 2009 11:37 AM | LINK

    Found a vedio which is helpful http://blogs.msdn.com/swiss_dpe_team/archive/2008/04/04/crud-operations-with-optimistic-locking-using-silverlight-2-beta1-wcf-and-linq-to-sql-inserts-updates-and-deletes.aspx , but he is updating in a batch in a DataGrid, how can we do it in a way update one record and do a postback.

  • yifung

    yifung

    Contributor

    3937 Points

    637 Posts

    Microsoft

    Re: Questions about DataGrid + DataForm

    May 19, 2009 05:10 PM | LINK

    In Silverlight 3, you'll be able to listen to EndedEdit on the DataGrid.  When a row has ended edit, you can push the value to the server.  In Silverlight 2, the DataGrid does not have the EndedEdit event so you would need to batch them up or your can implement IEditableObject.  If you do that, then you could push the changes back when IEditableObject.EndEdit is called.

    Yifung Lin [MSFT]
  • showen

    showen

    0 Points

    4 Posts

    Re: Questions about DataGrid + DataForm

    May 20, 2009 12:57 PM | LINK

    yes, you are right.

    'DataGrid_RowEditEnded' that's the one I'm after.

    thanks 

  • narayans

    narayans

    Member

    38 Points

    32 Posts

    Re: Questions about DataGrid + DataForm

    Aug 15, 2009 04:48 AM | LINK

    The other thing you can do is bind to the DomainDataSource's HasChanges dependency property like so:

    <ria:DomainDataSource x:Name="EntityDataSource" LoadSize="20" PageSize="10" AutoLoad="True">

    <ria:DomainDataSource.DomainContext>

    <app:MyAppContext/>

    </ria:DomainDataSource.DomainContext>

    </ria:DomainDataSource>

    <StackPanel Orientation="Horizontal">

    <Button Name="SaveButton" Content="Save" Click="Save_Click" IsEnabled="{Binding HasChanges, ElementName=EntityDataSource}" />

    <Button Name="DiscardButton" Content="Discard" Click="Discard_Click" IsEnabled="{Binding HasChanges, ElementName=EntityDataSource}"/>

    </StackPanel>

    in the xaml.cs:

            private void Save_Click(object sender, RoutedEventArgs e)
            {
                EntityDataSource.DomainContext.SubmitChanges();
            }
    
            private void Discard_Click(object sender, RoutedEventArgs e)
            {
                EntityDataSource.DomainContext.RejectChanges();
            }
    
     

     This way, you can allow the user to make edits to numerous records and choose to either commit the update or to discard all the changes.