我有两个表用于客户/公司,一个表用于该公司的代表。我在WCF中编写了一个方法,我加入了两个表,以便它们一起工作。应该怎么办,如果我在一个组合框中选择一个客户/公司,第二个组合框应该填充该公司的代表。
WCF
public List<Represetative> GetRepByComp(string CompanyId)
{
TruckDb db = new TruckDb();
List<Represetative> result = new List<Represetative>();
Represetative x = new Represetative();
Company o = new Company();
var filter = (from reps in db.Represetatives
join company in db.Companies on reps.Id equals company.Id
where company.Id == int.Parse(CompanyId)
select reps);
foreach (var item in filter)
{
result.Add(new Represetative()
{
Id = item.Id,
Name = item.Name
});
}
return result;
}
WPF
private async Task LoadClient(TruckServiceClient TSC, ComboBox combobox)
{
List<ClientItems> clientItems = new List<ClientItems>();
foreach (var item in await TSC.GetCompaniesAsync())
clientItems.Add(new ClientItems { Client = item.Name });
combobox.ItemsSource = (clientItems.ToArray());
combobox.IsEnabled = true;
combobox.SelectedIndex = 1;
}
public class ClientItems
{
public int Id { get; set; }
public string Client { get; set; }
public string RepId { get; set; }
public override string ToString()
{
return Client;
}
}
我的问题是为代表组合框创建一个方法,以便它响应地使用客户/公司组合框,任何想法?
答案 0 :(得分:0)
正如Chris所说,订阅SelectionChanged事件:
<ion-item>
背后的相应代码:
<ComboBox x:Name="comboBoxCompanies"
SelectionChanged="ComboBoxCompaniesSelectionChanged" />
此致