Skip to main content
Home Forums Silverlight Programming Silverlight Controls and Silverlight Toolkit Questions about DataGrid + DataForm
6 replies. Latest Post by narayans on August 15, 2009.
(0)
showen
Member
0 points
4 Posts
05-18-2009 9:07 AM |
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
Contributor
3313 points
540 Posts
05-18-2009 2:06 PM |
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
05-18-2009 5:52 PM |
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
05-19-2009 7:37 AM |
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.
05-19-2009 1:10 PM |
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.
05-20-2009 8:57 AM |
yes, you are right.
'DataGrid_RowEditEnded' that's the one I'm after.
narayans
38 points
19 Posts
08-15-2009 12:48 AM |
The other thing you can do is bind to the DomainDataSource's HasChanges dependency property like so:
<
</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.