I’d like to change a DataGrid’s column width, but I keep receiving an error.
This is how I fill in the DataGrid:
tabel.ItemsSource = Item.getItemByCategory(category).DefaultView;
getItemByCategory is a static method of the Item class which return a DataTable.
This is how I try to resize the column:
tabel.Columns[1].Width = 100;
And this is the error I receive:
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
For some reason, tabel.Columns.Count == 0. Although immediately after it is being shown there are 4 column displayed.
Could I get some help in resizing the columns?
Try something like that:
XAML file:
Code-behind file: