绑定到列表框的组合框数据不会显示显示成员

时间:2013-07-26 15:10:22

标签: c# .net sql wpf

我有一个组合框,用于填充数据库中的数据,该数据库基于列表框选择,通过SQL查询填充给定列表框中的数据。问题是显示成员属性不会显示。我不会显示后端sql,因为它工作正常,列表框实际上填充不是显示成员。所以列表框中的数据是空白的。

以下是代码:

Combobox方法:

private void populateFromMedication()
{
    MedicationList medicationItem = new MedicationList();

    // if item is selected
    if( !( ( Locations )cmbLocationDescriptionList.SelectedItem == null ) )
    {
        // set location to be the seletect location from the combo
        location = ( Locations )cmbLocationDescriptionList.SelectedItem;

        List<MedicationList> fromMedicatitionList = new List<MedicationList>();
        // retrieve a list of medication from the database
        fromMedicatitionList = LocationData.RetrieveMedicationByLocation( location.LocationID, GlobalVariables.SelectedResident.ResidentID );
        //bind the list for to the medication list
        lstMedicationForCurrentLocation.ItemsSource = fromMedicatitionList;

        lstMedicationForCurrentLocation.DisplayMemberPath = "Description";        
    } 
}

表单初始化:

public FormInitialize()
{
    InitializeComponent();
    LoadData();
    LoadResidentData();
    populateFromMedication();
}

MedicationList类:

           public class MedicationList
{

    public int MedicationID { get; set; }



    public string Description
    {
        get
        {
            return Description;
        }
        set
        {
            Description = value;
            OnPropertyChanged( "Description" );
        }
    }
}

1 个答案:

答案 0 :(得分:1)

您需要检查

1)MedicationList中有一个名称为Description的属性,OnPropertyChanged已应用于其设置者。

string _Description;
public string Description
{
    get
    {
        return _Description;
    }
    set
    {
        _Description = value;
        OnPropertyChanged("Description");
    }
}

有关OnPropertyChanged的更多信息,请阅读this

2)在提供Displaymember之前尝试提供Itemsource