TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Muruli madhav
NA
205
3.7k
C# WPF How to bind a nested class to nested datagrid
Apr 30 2020 12:36 AM
in WPF, How to bind data from nested classs to a nested datagrid? Why nested datagrid unable to read the class? what error i am doing?
public
class
Student
{
public
int
Id {
get
;
set
; }
public
string
Name {
get
;
set
; }
public
DateTime Birthday {
get
;
set
; }
public
Marks myMarks {
get
;
set
; }
}
public
class
Marks
{
public
double
English {
get
;
set
; }
public
double
Maths {
get
;
set
; }
public
double
Science {
get
;
set
; }
}
itemsource for main-datagrid
private
void
Page_Loaded(
object
sender, RoutedEventArgs e)
{
List<Student> myStudents =
new
List<Student>();
Marks JohnMark =
new
Marks();
JohnMark.English = 75;
JohnMark.Maths = 85;
JohnMark.Science = 95;
Marks RichardMark =
new
Marks();
RichardMark.English = 70;
RichardMark.Maths = 80;
RichardMark.Science = 90;
Marks SamMark =
new
Marks();
SamMark.English = 72;
SamMark.Maths = 82;
SamMark.Science = 92;
myStudents.Add(
new
Student() { Id = 1, Name =
"John Doe"
, Birthday =
new
DateTime(1971, 7, 23), myMarks = JohnMark });
myStudents.Add(
new
Student() { Id = 2, Name =
"Richard Doe"
, Birthday =
new
DateTime(1974, 1, 17), myMarks = RichardMark });
myStudents.Add(
new
Student() { Id = 3, Name =
"Sammy Doe"
, Birthday =
new
DateTime(1991, 9, 2), myMarks = SamMark });
DG_myStudents.ItemsSource = myStudents;
}
and below is my XAML code, Am i doing any error in class structure? Please help me.
<DataGrid x:Name=
"DG_myStudents"
RowDetailsVisibilityMode=
"Visible"
>
<DataGrid.RowDetailsTemplate>
<DataTemplate>
<DataGrid x:Name=
"DG_myMarks"
ItemsSource=
"{Binding myMarks}"
/>
</DataTemplate>
</DataGrid.RowDetailsTemplate>
</DataGrid>
Nothing, the nested datagrid "DG_myMarks" is not showing any data. And when i bind "myMarks" to a label to just to see any thing happening there, then label is showing "Marks class name" like this "MyNameSpace.myPage+Marks"
Reply
Answers (
3
)
How can i make duplicate controls in c#?
C# datagridview sum two column and subtract with Value.