Skip to main content

Microsoft Silverlight

Answered Question Questions about DataGrid + DataFormRSS Feed

(0)

showen
showen

Member

Member

0 points

4 Posts

Questions about DataGrid + DataForm

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

yifung
yifung

Contributor

Contributor

3313 points

540 Posts

Microsoft

Re: Questions about DataGrid + DataForm

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

Member

Member

0 points

4 Posts

Re: Questions about DataGrid + DataForm

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

Member

Member

0 points

4 Posts

Re: Questions about DataGrid + DataForm

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

Contributor

3313 points

540 Posts

Microsoft
Answered Question

Re: Questions about DataGrid + DataForm

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

Member

Member

0 points

4 Posts

Re: Questions about DataGrid + DataForm

yes, you are right.

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

thanks 

narayans
narayans

Member

Member

38 points

19 Posts

Re: Questions about DataGrid + DataForm

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.

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities