I am writing a simple program in C # using wpf, a semblance of a base, I understand that it would be easier to solve this problem using subd and entity framework, but the point is that you need to solve this way
So, I have a text file from which I need to load data into the date grid.
I have a class that describes a line from this text file, here it is:
public class Student
{
public int Id { get; set; }
public string Name { get; set; }
public string LastName { get; set; }
public string MidName { get; set; }
public int Informatics { get; set; }
public int Maths { get; set; }
public int Physics { get; set; }
public double Score { get; set; }
}
The scores field, for data from the program (the arithmetic mean of the student's grades)
And I have a datagrid in which I need to output data:
<DataGrid x:Name="DGridStudents" IsReadOnly="True" AutoGenerateColumns="False" HorizontalAlignment="Left" Height="329" Margin="57,15,0,0" VerticalAlignment="Top" Width="736">
<DataGrid.Columns>
<DataGridTextColumn Header="ID" Width="*" Binding="{Binding Id}"/>
<DataGridTextColumn Header="Name" Width="*" Binding="{Binding Name}"/>
<DataGridTextColumn Header="LastName" Width="*" Binding="{Binding LastName}"/>
<DataGridTextColumn Header="MidName" Width="*" Binding="{Binding MidName}"/>
<DataGridTextColumn Header="Informatics" Width="*" Binding="{Binding Informatics}"/>
<DataGridTextColumn Header="Maths" Width="*" Binding="{Binding Maths}"/>
<DataGridTextColumn Header="Physics" Width="*" Binding="{Binding Physics}"/>
<DataGridTextColumn Header="Score" Width="*" Binding="{Binding Score}"/>
</DataGrid.Columns>
</DataGrid>
Thus, I used to fill the DataGrid, now I needed to add the Score field (Arithmetic mean of grades for subjects)
List<Student> list = new List<Student>();
using (StreamReader sr = new StreamReader(fileName, true))
{
string line;
while ((line = sr.ReadLine()) != null)
{
var parsed = line.Split(' ');
list.Add(new Student
(
Convert.ToInt32(parsed[0]),
parsed[1],
parsed[2],
parsed[3],
Convert.ToInt32(parsed[4]),
Convert.ToInt32(parsed[5]),
Convert.ToInt32(parsed[6])
));
}
}
DGridStudents.ItemsSource = list;
Please tell me how can I do this using data bindings without using the MVVM pattern?
Example of a line from a text file:
1 Benedict Timothy-Carlton Cumberbatch 5 5 5