Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7799995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:29:21+00:00 2026-06-02T00:29:21+00:00

I have Student table, Course table and a StudentCourse table. On my WPF, I’m

  • 0

I have Student table, Course table and a StudentCourse table. On my WPF, I’m making “Student” selections with combo box. How can I display the corresponding Course and its properties(CourseID, CourseName, Credit) in a listview, using ObservableCollection?. Here’s my code for the combo box SelectionChanged event

 private void comboBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        int MySelect = (int)this.comboBox1.SelectedValue;
        var SelectedStudent = db.Students.Include("StudentCourses.Course").SingleOrDefault(f => f.StudentID == MySelect);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T00:29:23+00:00Added an answer on June 2, 2026 at 12:29 am

    If you’re not already, I would highly recommend using a MVVM styled approach. Your ListView’s ItemsSource should be bound to an ObservableCollection in your ViewModel and your ComboBox’s SelectedItem should also be bound to a propety on your ViewModel. When the SelectedItem changes and calls the property’s setter update the ObservableCollection that your ListView is bound to.

    Update:

    Here’s a partially implemented solution:

    XAML:

    <DockPanel>
        <ComboBox ItemsSource="{Binding Students}" SelectedItem="{Binding SelectedComboItem}" DockPanel.Dock="Top">
            <ComboBox.ItemTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Name}"/>
                </DataTemplate>
            </ComboBox.ItemTemplate>
        </ComboBox>
    
        <ListView ItemsSource="{Binding StudentCourses}">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <StackPanel>
                        <TextBlock Text="{Binding Name, StringFormat={}Name: {0}}"/>
                        <TextBlock Text="{Binding Id, StringFormat={}Id: {0}}"/>
                        <TextBlock Text="{Binding Credit, StringFormat={}Credit: {0}}"/>
                    </StackPanel>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </DockPanel>
    

    Code:

    public class Student
    {
        public string Name { get; set; }
        public List<string> CourseIds { get; set; }
    } 
    
    
    public class Course
    {
        public string Name { get; set; }
        public string Id { get; set; }
        public int Credit { get; set; }
    }
    
    
    public class ViewModel : INotifyPropertyChanged
    {
        public ObservableCollection<Course> StudentCourses { get; set; }
        public ObservableCollection<Student> Students { get; set; }
    
    
        public Student SelectedComboItem
        {
            get { return selectedComboItem_; }
            set {
                selectedComboItem_ = value;
                StudentCourses.Clear();
                foreach(Course course in courses_)
                    if(selectedComboItem_.CourseIds.Contains(course.Id))
                        StudentCourses.Add(course);
                PropertyChanged(this, new PropertyChangedEventArgs("SelectedComboItem"))    ;
            }
        }
    
    
        private List<Course> courses_ = new List<Course>();
        private Student selectedComboItem_;
    
    
        ... // Read DB and build collections
    
        public event PropertyChangedEventHandler PropertyChanged;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 3 tables Student, Course, and the linking table StudentCourse, how do i
I have a table of student scores. Students can take the test multiple times,
I have a timetable for student so they can attend to course on the
I have a USER table and a COURSE table. A USER can have many
I have a table that looks like this for about ~30 students: StudentID Course*
I have three tables. The designs were like student table create table student (studID
I have bind 2 separate tables using BindingSource. Left grid contains student table and
I have a database table named 'student' in which there is one column named
I have a table that includes some student group name, lesson time, day names
i have a table which consists of student details like roll no, Name, age.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.