You can set any headers you want. Just add your columns:
DataTable.Columns.Add("I am a Column Header!:)");
Let's see an example of MVVM:
public class YourViewModel : ViewModelBase { public YourViewModel() { PopulateDataTable(); } private void PopulateDataTable() { var _ds = new DataSet("Test"); employeeDataTable = new DataTable(); employeeDataTable = _ds.Tables.Add("DT"); for (int i = 0; i < 20; i++) {
Your XAML:
<DataGrid ItemsSource="{Binding EmployeeDataTable}" />
Update:
Check out the sample code:
Your XAML:
<DataGrid Name="dataGrid"/>
Your code:
//constructor of the Window public MainWindow() { InitializeComponent(); PopulateDataGrid(); } DataTable employeeDataTable = new DataTable(); private void PopulateDataGrid() { var _ds = new DataSet("Test"); employeeDataTable = _ds.Tables.Add("DT"); for (int i = 0; i < 10; i++)//create columns { employeeDataTable.Columns.Add("I am a column!:)"); } for (int i = 0; i < 50; i++)//fill data to rows { var theRow = employeeDataTable.NewRow(); for (int j = 0; j < 10; j++) { if (j % 2 == 0) theRow[j] = "a"; else theRow[j] = "b"; } employeeDataTable.Rows.Add(theRow); } dataGrid.ItemsSource = employeeDataTable.AsDataView(); }
source share