I use the DataTable
for adding items to a DataGridView
and the DataGridRow
for getting the select items out of it in WPF but the silverlight appears not to have those types. I would like to know what the appropriate way is to add data and get them back to and from the DataGridView
in silverlight since those things are not available in this framework.
You don't need to bind your data with the data grid view like that at all. (By using DataTable
). Instead you you can make a list of your models and directly bind it to the item source of the grid view. For example:
// Example Model
public class MyModel{
public int Id {get; set;}
public String Title {get; set;
}
List<MyModel> MyList = new List<MyModel>(){ new MyModel{ Id = 1, Title = "Jack"}};
MyDataGridView.ItemSource = MyList;
And to get the selected row you can:
var Row = (MyModel) MyDataGridView.SelectedItem;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.