Net 4.0 App中有DataGrid
个数据。对于选定的行,我获取其中一列的值并将其传递给WCF服务的异步方法。这个方法可以传递这个值吗?
btn_Click(object sender, RoutedEventArgs e) {
DataRowView rv = (DataRowView)dgData.SelectedItem;
rv["TimeBeg"] = DateTime.Now.ToString("h:mm:ss");
string val=rv["Id"].ToString();
srAsync.ServClient clP = new srAsync.ServClient();
clP.MethodCompleted += cl_MethodComplete;
clP.MethodAsync(val);
}
在调用之后,用户可以选择另一个DataGrid
项,并为它们调用Async
方法,但在完整方法中,我需要使用此值调用另一个方法并更新行{{1 }}
DataGrid
答案 0 :(得分:1)
我要做的是使用lambda函数将用户点击的行传递给处理程序:
btn_Click(object sender, RoutedEventArgs e) {
DataRowView rv = (DataRowView)dgData.SelectedItem;
rv["TimeBeg"] = DateTime.Now.ToString("h:mm:ss");
string val = rv["Id"].ToString();
srAsync.ServClient clP = new srAsync.ServClient();
clP.MethodCompleted += (currentSender, currentE) => cl_MethodComplete(currentSender, currentE, rv);
clP.MethodAsync(val);
}
当然,您必须向cl_MethodComplete
添加另一个参数,该参数将能够在原始行上运行:
private void cl_MethodComplete(object sender, srA.MethodCompletedEventArgs e, DataRowView originalRow) {
originalRow["TimeEnd"] = DateTime.Now.ToString("h:mm:ss");
sr.ServClient clP = new sr.ServClient();
clP.AnotherMethod(val);
...