【问题标题】:Combo box data bound to listbox wont show display member绑定到列表框的组合框数据不会显示显示成员
【发布时间】:2013-07-26 22:30:11
【问题描述】:

我有一个组合框,用于填充数据库中的数据,该组合框基于列表框选择通过 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();
}

MedicationList 类:

           public class MedicationList
{

    public int MedicationID { get; set; }



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

【问题讨论】:

    标签: c# .net sql wpf


    【解决方案1】:

    你需要检查一下

    1) MedicationList 中有一个名为 Description 的属性,并且 OnPropertyChanged 应用于其设置器。

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

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

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

    【讨论】:

    • @Mark:在你的类 MedicationList 中是否有一个名为 Description 的属性?
    • 如何更改 onPropertyChanged?
    • 在此上下文中不存在关于属性更改?
    猜你喜欢
    • 1970-01-01
    • 2016-09-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多