C# 使用实体框架在wpf datagrid中级联组合框
我正在使用实体框架模型使用数据模板列(而不是DataGridComboxColumn)中的组合框。在datagrid的第一列中。组合框应显示国家,在第二列中,组合框应显示国家。当一行中的国家发生更改时,第二列组合中的状态必须根据该行中的国家进行更新。我有三个表,即国家(国家id int、国家名称)、州(国家id、国家id、国家名称)和地区(国家id、国家id、地区id、地区名称)。我有四个.cs文件 1:testEntities.csC# 使用实体框架在wpf datagrid中级联组合框,c#,wpf,C#,Wpf,我正在使用实体框架模型使用数据模板列(而不是DataGridComboxColumn)中的组合框。在datagrid的第一列中。组合框应显示国家,在第二列中,组合框应显示国家。当一行中的国家发生更改时,第二列组合中的状态必须根据该行中的国家进行更新。我有三个表,即国家(国家id int、国家名称)、州(国家id、国家id、国家名称)和地区(国家id、国家id、地区id、地区名称)。我有四个.cs文件 1:testEntities.cs public partial class testEntit
public partial class testEntities : DbContext
{
public testEntities()
: base("name=testEntities")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}
public DbSet<country> countries { get; set; }
public DbSet<district> districts { get; set; }
public DbSet<state> states { get; set; }
}
public partial class state
{
public Nullable<byte> country_id { get; set; }
public byte state_id { get; set; }
public string state_name { get; set; }
}
public partial class district
{
public Nullable<byte> country_id { get; set; }
public Nullable<byte> state_id { get; set; }
public byte district_id { get; set; }
public string district_name { get; set; }
}
3:-state.cs
public partial class testEntities : DbContext
{
public testEntities()
: base("name=testEntities")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}
public DbSet<country> countries { get; set; }
public DbSet<district> districts { get; set; }
public DbSet<state> states { get; set; }
}
public partial class state
{
public Nullable<byte> country_id { get; set; }
public byte state_id { get; set; }
public string state_name { get; set; }
}
public partial class district
{
public Nullable<byte> country_id { get; set; }
public Nullable<byte> state_id { get; set; }
public byte district_id { get; set; }
public string district_name { get; set; }
}
提前非常感谢这是一个开始using System.Windows.Data;
private void Window_Loaded(object sender, RoutedEventArgs e)
{
testEntities te= new testEntities ();
CollectionViewSource countryViewSource = ((CollectionViewSource)(this.FindResource("countryViewSource")));
CollectionViewSource stateViewSource = ((CollectionViewSource)(this.FindResource("stateViewSource")));
CollectionViewSource districtViewSource = ((CollectionViewSource)(this.FindResource("districtViewSource")));
te.countries .Load();
te.states .Load ();
te.districts .Load ();
countryViewSource.Source = te.countries.Local;
stateViewSource.Source = te.states.Local;
districtViewSource.Source = te.countries.Local;
}
如果州在一个县,那么把它们放在该国
public partial class country
{
public byte country_id { get; set; }
public string country_name { get; set; }
public DbSet<state> states { get; set; }
}
您好,感谢您回答我的问题,在datagrid中级联cb,但它不工作。我可以知道你的电子邮件,以便我可以发送完整的代码thnaks我的电子邮件nirankar。kaushik@gmail.com