WEB开发网
开发学院图形图像Flash Silverlight 2 - Simple Editing of Web Service ... 阅读

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 referen

From there, I added in a Silverlight project and created a simple UI.

Silverlight 2 - Simple Editing of Web Service Data in a DataGrid

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.

上一页  1 2 3 4  下一页

Tags:Silverlight Simple Editing

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接