1

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

这是代码:

组合框方法:

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();
}

药物清单类:

           public class MedicationList
{

    public int MedicationID { get; set; }



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

1 回答 1

1

你需要检查一下

MedicationList1)名称中有一个属性,DescriptionOnPropertyChanged应用于其设置器。

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

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

Displaymember2)在提供之前尝试给予Itemsource

于 2013-07-26T15:15:34.150 回答