我在gridview中有一个wpf组合框,它有dataview作为绑定源。组合框填充值,但在加载组合框时,所选项始终为空。
组合框绑定的对象:
public class ChargeCodeValidValues
{
#region Properties
public DataTable ChargeCodesValidValuesTable { get; set; }
public DataView dvChargeCodeValidValues { get; set; }
#region Properties
//public int Id { get; set; }
//public int Code { get; set; }
//public string Description { get; set; }
#endregion
// public ChargeCodeValidValue() { }
//public ChargeCodeValidValue(DataRow dr)
//{
// Id = dr.Field<int>("Id");
// Code = dr.Field<int>("Code");
// Description = dr.Field<string>("Description");
//}
#endregion
#region Constructor
public ChargeCodeValidValues()
{
LoadChargeCodesValidValues();
}
public void LoadChargeCodesValidValues()
{
Database db = new Database();
DataTable dataTable = db.ExecuteQuery("upGet_ChargeCodesValidValues", "ChargeCodesValidValues", "ID");
this.ChargeCodesValidValuesTable = dataTable;
this.dvChargeCodeValidValues = ChargeCodesValidValuesTable.DefaultView;
}
//public static void GetChargeCodeValidValues()
//{
// Database db = new Database();
// DataTable dataTable = db.ExecuteQuery("upGet_ChargeCodesValidValues", "ChargeCodesValidValues", "ID");
//}
#endregion
}
public class ChargeCodeValidValue
{
#region Properties
public int Id { get; set; }
public int Code { get; set; }
public string Description { get; set; }
#endregion
public ChargeCodeValidValue() { }
public ChargeCodeValidValue(DataRow dr)
{
Id = dr.Field<int>("Id");
Code = dr.Field<int>("Code");
Description = dr.Field<string>("Description");
}
public void LoadChargeCodeValidValue(DataRow dr)
{
Id = dr.Field<int>("Id");
Code = dr.Field<int>("Code");
Description = dr.Field<string>("Description");
}
}
XAML:
<DataTemplate x:Key="combodescriptionTemplate">
<ComboBox
Name="cboCombo"
ItemsSource="{Binding dvChargeCodeValidValues}"
DisplayMemberPath="Description"
SelectedItem="Description"
>
<ComboBox.DataContext>
<Objects:ChargeCodeValidValues/>
</ComboBox.DataContext>
</ComboBox>
</DataTemplate>
<local:TotalCellTemplateSelector x:Key="totalcellTemplateSelector"
combodescriptionTemplate="{StaticResource combodescriptionTemplate}"/>
gridview专栏:
<dxg:GridColumn Header="Description" FieldName="Description" Width="Auto" MinWidth="132" AllowMoving="False" CellTemplateSelector="{StaticResource totalcellTemplateSelector}" /> -->
此列默认为文本框。它会根据其他列的值
更改为组合框Combobox所选项目始终为空。我知道这是一个具有约束力的问题,但我无法弄明白,我是wpf的新手。
有人可以帮忙吗