Silverlight 2 - Simple Editing of Web Service Data in a DataGrid
2008-10-24 11:46:57 来源:WEB开发网From there, I added in a Silverlight project and created a simple UI.
It's just a DataGrid and a couple of buttons. I added a service reference to my WCF service in order to get a proxy class to use to call the service asynchronously.
In order to populate the DataGrid, I make a call to my webservice, get the data, convert the results into an ObservableCollection<T> where T is a local class that I called DataRow;
public enum RowState
{
Clean,
Modified,
Inserted
}
public class DataRow
{
public DataRow()
{
State = RowState.Clean;
}
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public int Age { get; set; }
public RowState State { get; set; }
}
and then I just set up the UI so that it data binds 4 text box columns to the properties on my DataRow class.
I use that RowState enum to determine for each row whether it has been modified or inserted and I also keep a separate List<DataRow> for any rows that have been deleted.
From a UI perspective, I couldn't find a simple property which I could set to get the DataGrid to display a "blank insert row" so I just added a keyboard handler for the Insert key and the Delete key and that's how I handle insert/delete from the UI. For insert, I just add a blank DataRow instance into the ObservableCollection.
Tags:Silverlight Simple Editing
编辑录入:爽爽 [复制链接] [打 印]- ››Silverlight for Windows Phone 7开发系列(1):...
- ››Silverlight for Windows Phone 7开发系列(2):...
- ››Silverlight for Windows Phone 7开发系列(3):...
- ››Silverlight for Windows Phone 7开发系列(4):...
- ››Silverlight for Symbian
- ››Silverlight3系列(四)数据绑定 Data Binding 1
- ››Simple Cloud API:编写可移植的、可互操作的云应...
- ››silverlight2 游戏 1 你能坚持多少秒
- ››Silverlight开发实践--PicZoomShow
- ››Silverlight自定义控件开发 - 令人懊恼的OnApplyT...
- ››Silverlight 2 RTW中ToolTipService.ToolTip不继承...
- ››Silverlight 鼠标滚轮组件“Silverlight.FX”
更多精彩
赞助商链接