The reason is that the
DataGridView
can display only one level of
Tabular data
. It cannot show
Tables
nested inside a
cell
. To get the desired result modify the code as follows:
namespace ShowEntityOfInherited
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
List<student> All = new List<student>();
Student s1 = new Student();
s1.StudentName = "Moumit";
s1.StudentRoll = 10;
s1.KlassName = "V";
Student s2 = new Student();
s2.StudentName = "Moumit1";
s2.StudentRoll = 11;
s2.KlassName = "VI";
All.Add(s1);
All.Add(s2);
dgv.BindingContext = new BindingContext();
dgv.DataSource = All;
dgv.Columns["StudentName"].HeaderText = "Name";
dgv.Columns["StudentRoll"].HeaderText = "Roll";
dgv.Columns["KlassName"].HeaderText = "Klass";
}
}
public class Student
{
public string StudentName { get; set; }
public int StudentRoll { get; set; }
public string KlassName { get; set; }
}
}