采用为DataGrid添加CurrentCellChanged事件 ,来处理获得的行数据
private void dg_Device_CurrentCellChanged(object sender, EventArgs e)
{
DataGrid d = sender as DataGrid;
//获取DataGrid数据
List<Device> list=new List<Device>();
if(d!=null)
{
foreach(Device v in d.ItemsSource)
list.Add(v);
}
//获得当前选择的行
//这里就可以处理获取行的数据了
//以删除此行为例
Device device = (Device)d.SelectedItem;
if (device != null)
{
this.device = device;
list.Remove(device);
}
//删除后重新赋值给DataGrid
dg_Device.ItemsSource = list;
}