Hi there,
While using a tutorial found here
I Programmer
I worked through the example and adapted it for your needs.
public partial class MainWindow : Window
{
public struct MyData
{
public int id { set; get; }
public string title { set; get; }
public int jobint { set; get; }
public DateTime lastrun { set; get; }
public DateTime nextrun { set; get; }
}
public MainWindow()
{
InitializeComponent();
DataGridTextColumn col1 = new DataGridTextColumn();
DataGridTextColumn col2 = new DataGridTextColumn();
DataGridTextColumn col3 = new DataGridTextColumn();
DataGridTextColumn col4 = new DataGridTextColumn();
DataGridTextColumn col5 = new DataGridTextColumn();
myDataGrid.Columns.Add(col1);
myDataGrid.Columns.Add(col2);
myDataGrid.Columns.Add(col3);
myDataGrid.Columns.Add(col4);
myDataGrid.Columns.Add(col5);
col1.Binding = new Binding("id");
col2.Binding = new Binding("title");
col3.Binding = new Binding("jobint");
col4.Binding = new Binding("lastrun");
col5.Binding = new Binding("nextrun");
col1.Header = "ID";
col2.Header = "title";
col3.Header = "jobint";
col4.Header = "lastrun";
col5.Header = "nextrun";
myDataGrid.Items.Add(new MyData { id = 1, title = "Test", jobint = 2, lastrun = new DateTime(), nextrun = new DateTime() });
myDataGrid.Items.Add(new MyData { id = 12, title = "Test2", jobint = 24, lastrun = new DateTime(), nextrun = new DateTime() });
}
}
The code behind shown above seems to be fairly straight forward. The XAML is as follows:
<Window x:Class="DataGridTester.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<DataGrid x:Name="myDataGrid"/>
</Grid>
</Window>
Hope this helps
Laurence
(I've had a lot of problems posting this answer, apologies if it doesn't display correctly)