我有这段代码使用异步方法填充了三个组合框
private async void FrmEmployee_Load(object sender, EventArgs e)
{
cmbCountry.Properties.DataSource =await emp.GetCountry();
cmbCountry.Properties.DisplayMember = "Nom";
cmbCountry.Properties.ValueMember = "ID_Country";
}
private async void cmbCity_Enter(object sender, EventArgs e)
{
cmbCity.Properties.DataSource =await emp.GetCity(Convert.ToInt32(cmbCountry.EditValue));
cmbCity.Properties.DisplayMember = "Willaya";
cmbCity.Properties.ValueMember = "Numéro";
}
private async void cmbTown_Enter(object sender, EventArgs e)
{
cmbTown.Properties.DataSource =await emp.GetTown(Convert.ToInt32(cmbCity.EditValue));
cmbTown.Properties.DisplayMember = "Commune";
cmbTown.Properties.ValueMember = "ID_Town";
}
并且我有这段代码可在gridView的DoubleClick上触发
private async void gridView1_DoubleClick(object sender, EventArgs e)
{
cmbCountry.Text = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Pays").ToString();
cmbCity_Enter(sender, e);
cmbCity.Text = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Willaya").ToString();
cmbTown_Enter(sender, e);
cmbTown.Text = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Commune").ToString();
}
在我将此代码与同步一起使用之前,该代码非常有效,但现在与async不兼容,这是为什么?以及如何解决此问题,谢谢。