After loading my data into a DataGrid using WPF:
dataGrid1.DataContext = db.Select_Drawing_Numbers();
dataGrid1.Columns[0].Width = 10;
But I get an error:
Index is out of range. Please select a non-zero, non-negative integer.
How can I make sure the data is bound before calling Columns[0]?
Try hooking into the
Loadedevent of theDataGrid. The issue you are having is that theDataGriddoesn’t actually have any values loaded into it (and therefore has no columns/rows) until it isLoaded.