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 9209713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:54:37+00:00 2026-06-18T00:54:37+00:00

Student class public class Student { string name; List<SubjectInfo> subjectInfoList; …. } List<SubjectInfo> List

  • 0

Student class

public class Student
{
    string name;        

    List<SubjectInfo> subjectInfoList;        

    ....
}

List<SubjectInfo> List can have different number of SubjectInfo objects for different students.

SubjectInfo class

public class SubjectInfo
{
    string subjectCode;

    int marks;

    ...
}

I want to display student object detail on a window. Since List have different number of object count I generated these from code behind.

int i = 10;

        foreach (SubjectInfo info in student.SubjectInfoList)
        {
            TextBox tb = new TextBox();
            tb.Width = 200;
            tb.Height = 20;
            tb.Margin = new Thickness(10, i, 0, 0);
            StudentDataGrid.Children.Add(tb);
            i += 60;
        }

I would like to bind this List list from code behind. But I have no idea of doing that.
I want to bind marks property of student.SubjectInfoList

Please help me with binding list object properties from codebehind.

EDIT
This is the sample student object;

Student student = new Student("Joe", new List<SubjectInfo>() { new SubjectInfo("Subject1", 50), new SubjectInfo("Subject2", 70)});  

My window should like this;
enter image description here

NOTE if student doing 4 subjects total TextBox count is 5.

  • 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-18T00:54:38+00:00Added an answer on June 18, 2026 at 12:54 am

    Pure XAML solution:

    <Window  (... your window attributes) >
    
        ....
    
        <Grid x:Name="StudentDataGrid">
            <ListView ItemsSource="{Binding SubjectInfoList}">
                <ListView.ItemTemplate>
                    <DataTemplate DataType="{x:Type local:SubjectInfo}">
                        <TextBox Text="{Binding Marks}"/>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>
        </Grid>
    </Window>
    

    But to have it work you have to transform your fields to public properties:

    public class Student
    {
        string name;        
    
        public List<SubjectInfo> SubjectInfoList { get; set; }
    
        ....
    }
    

    and:

    public class SubjectInfo
    {
        string subjectCode;
    
        public int Marks { get; set; }
    
        ...
    }
    

    UPDATE

    XAML:

    <Window x:Class="WpfApplication1.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:local="clr-namespace:WpfApplication1"
            Title="MainWindow" Height="350" Width="525">
    
    
        <Grid x:Name="StudentGrid">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
    
            <TextBlock Text="Student name :" Grid.Row="0" Grid.Column="0"/>
            <TextBlock Text="Student marks :" Grid.Row="1" Grid.Column="0"/>
    
            <TextBox Text="{Binding Name}" Grid.Row="0" Grid.Column="1" />
    
            <ListView Grid.Row="1" Grid.Column="1" ItemsSource="{Binding SubjectInfoList}" BorderThickness="0">
                <ListView.ItemTemplate>
                    <DataTemplate DataType="{x:Type local:SubjectInfo}">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="100"/>
                                <ColumnDefinition Width="50"/>
                            </Grid.ColumnDefinitions>
    
                            <TextBlock Grid.Column="0" Text="{Binding SubjectCode}"/>
                            <TextBox Grid.Column="1" Text="{Binding Marks}"/>
                        </Grid>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>
        </Grid>
    </Window>
    

    The code:

    using System.Collections.Generic;
    using System.Windows;
    
    namespace WpfApplication1
    {
        public partial class MainWindow : Window
        {
            public MainWindow()
            {
                InitializeComponent();
    
                Student student = new Student("Joe", new List<SubjectInfo>() { new SubjectInfo("Subject1", 50), new SubjectInfo("Subject2", 70) });
                StudentGrid.DataContext = student;
            }
        }
    
        public class Student
        {
            public string Name { get; set; }
            public List<SubjectInfo> SubjectInfoList { get; set; }
    
            public Student(string name, List<SubjectInfo> list)
            {
                Name = name;
                SubjectInfoList = list;
            }
        }
    
        public class SubjectInfo
        {
            public string SubjectCode { get; set; }
            public int Marks { get; set; }
    
            public SubjectInfo(string subjectCode, int marks)
            {
                SubjectCode = subjectCode;
                Marks = marks;
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Student class public class Student { string name; List<SubjectInfo> subjectInfoList; .... } List<SubjectInfo> List
Let's have this code : class student :IComparable , IComparable<student> { public string name
I have class student : public class Student { public string Name { get;
I have a class named Student public class Student { public string Name {
I have an ASP.NET WebService that returns an object of List public class Students
I'm having syntax troubles. public class Student { int StudentId; string Name; } public
I have these two classes: class Student { String name; String age ; }
I have the code as below. class Student : IPeople { private string name;
I have a custom class student as below: public class Student { public string
I have a document entity Student public class Student { public string Id {

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.