Привет!
Вот самый простой пример как можно программно добавить данные в DataGrid:
<DataGrid Name="dataGridView1" IsReadOnly="True" ColumnWidth="*" VerticalAlignment="Top"
CanUserResizeColumns="False" CanUserAddRows="False" CanUserDeleteRows="False"
CanUserReorderColumns="False" BorderThickness="0">
<DataGrid.Columns>
<DataGridTextColumn Header="Номер карты" Binding="{Binding Column1}"></DataGridTextColumn>
<DataGridTextColumn Header="Симптомы" Binding="{Binding Column2}"></DataGridTextColumn>
<DataGridTextColumn Header="Диагноз" Binding="{Binding Column3}"></DataGridTextColumn>
<DataGridTextColumn Header="Лечение" Binding="{Binding Column4}"></DataGridTextColumn>
<DataGridTextColumn Header="Дата приема" Binding="{Binding Column5}"></DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
using System.Windows;
namespace WpfApp2
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
dataGridView1.Items.Add(new TestData { Column1 = "Col1,Row1", Column2 = "Col2,Row1", Column3 = "Col3,Row1", Column4 = "Col4,Row1", Column5 = "Col5,Row1" });
dataGridView1.Items.Add(new TestData { Column1 = "Col1,Row2", Column2 = "Col2,Row2", Column3 = "Col3,Row2", Column4 = "Col4,Row2", Column5 = "Col5,Row2" });
dataGridView1.Items.Add(new TestData { Column1 = "Col1,Row3", Column2 = "Col2,Row3", Column3 = "Col3,Row3", Column4 = "Col4,Row3", Column5 = "Col5,Row3" });
}
}
public class TestData
{
public string Column1 { get; set; }
public string Column2 { get; set; }
public string Column3 { get; set; }
public string Column4 { get; set; }
public string Column5 { get; set; }
}
}
Результат: