3 つの DataGrid がある小さな Silverlight アプリケーションをプログラムしたいと考えています。各 Datagrid は、非同期メソッドを使用して Web サービスからデータを取得します。ここで、最初のデータ グリッドで Web サービスからデータを取得し、最初のデータ グリッドで選択した行のパラメーターを使用して 2 番目のデータ グリッドを取得し、最初の 2 つのデータ グリッドのパラメーターを使用して 3 番目のデータ グリッドを取得します。最初のデータグリッドは、イベント ハンドラーを登録し、非同期メソッドを使用して、MainPage メソッドでデータを取得します。
ここで私の問題は、SelectionChanged (イベント処理) メソッドで他のデータグリッドに非同期メソッドを使用していることです。データグリッド 2 で何かを選択してデータグリッド 1 に戻ると、すべてのデータグリッドが消えるため、この概念は間違っていると思います。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ServiceModel;
using Rebat.SymptomeService;
namespace Rebat
{
public partial class MainPage : UserControl
{
ServiceClient client = new ServiceClient();
public MainPage()
{
InitializeComponent();
ServiceClient client = new ServiceClient();
client.SymptomeListCompleted += new EventHandler<SymptomeListCompletedEventArgs>(client_SymptomeListCompleted);
client.SymptomeListAsync();
}
void client_SymptomeListCompleted(object sender, SymptomeListCompletedEventArgs e)
{
CustomerGrid.ItemsSource = e.Result;
}
void client_CustomerListCompleted(object sender, CustomerListCompletedEventArgs e)
{
CustomerGrid2.ItemsSource = e.Result;
}
void client_SalzListCompleted(object sender, SalzListCompletedEventArgs e)
{
SalzGrid.ItemsSource = e.Result;
}
private void CustomerGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
Symptome sympt = CustomerGrid.SelectedItem as Symptome;
client.CustomerListCompleted += new EventHandler<CustomerListCompletedEventArgs>(client_CustomerListCompleted);
client.CustomerListAsync(sympt.sId.ToString());
}
private void CustomerGrid2_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
Symptome2 sympt2 = CustomerGrid2.SelectedItem as Symptome2;
client.SalzListCompleted += new EventHandler<SalzListCompletedEventArgs>(client_SalzListCompleted);
//this is the PROBLEM:
client.SalzListAsync(sympt2.sy1.ToString(), sympt2.sy2.ToString());
}
}
}
何を変更する必要がありますか、または非同期メソッドをどのように使用する必要がありますか? イベント処理メソッド内で非同期メソッドを使用できますか? これは、Web サービスを使用する使用法に適用されますか?