Frage

I am having a problem with my Combobox. From the database I grab data from a programs column based on two other combo boxes (status and campus) and attempt to fill the combobox. The data from the first row in the db is the only data filling the combobox. The first row in db contains 172. A 1, 7, and 2 are added to the combo box. (Since I am new to Stackoverflow I cannot post images yet - sorry in adavance)

To get an idea here's how it is looking when I fill the combo box: https://www.dropbox.com/s/et4ty82suk9nkr9/tuitionEstimatorApp.jpg

Program Data:
https://www.dropbox.com/s/my07trwvh6pxr3l/programData.jpg

XAML

<telerik:RadComboBox x:Name="ProgramComboBox" ItemsSource="{Binding ProgramName}" />

CS

DataContext = Program.GetPrograms(status, campusSelection);

Program Class

    public class Program : INotifyPropertyChanged
{
    private string _programname;
    public string ProgramName
    {
        get { return _programname; }
        set
        {
            _programname = value; RaisePropertyChanged();
        }
    }



    private void RaisePropertyChanged([CallerMemberName] string caller = "")
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(caller));
        }
    }


    public event PropertyChangedEventHandler PropertyChanged;

    public static List<Program> GetPrograms(string status, string campus)
    {
        var context = new FTEDatabaseEntities();


        var query = context.Entity1
            .Where(p => p.dependency_status == status && p.campus == campus)
            .Select(p => p.program);


        return query.Distinct().Select(program => new Program() { ProgramName = program }).ToList();
    }
}

Any insight would be greatly appreciated.

War es hilfreich?

Lösung

You have to bind the combo box to an List (or enumerable) type. Your binding sees that the property "ProgramName" is of type IEnumerable<char> (aka string), and so populates itself that way.

It looks like you will want to create a new property of type List<Program> Programs or similar, and then use:

<telerik:RadComboBox x:Name="ProgramComboBox" ItemsSource="{Binding Programs}" />
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top