private static void OnColumnHeadersChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { var dataGrid = (DataGrid)d; dataGrid.AutoGenerateColumns = false; dataGrid.CanUserAddRows = false; dataGrid.CanUserDeleteRows = false; var headers = dataGrid.GetColumnHeadersSource(); if (headers == null) { return; } var count = headers.Count(); for (int i = 0; i < count; i++) { if (dataGrid.Columns.Count > i) { var column = (IndexColumn)dataGrid.Columns[i]; column.BindHeader(headers, i); } else { var templateColumn = new IndexColumn(dataGrid, headers, i); dataGrid.Columns.Add(templateColumn); } } }
private static void AddColumn(DataGrid dataGrid, int i) { if (dataGrid.Columns.Count > i) { var column = dataGrid.Columns[i] as IndexColumn; if (column == null) { throw new InvalidOperationException(); } } else { var templateColumn = new IndexColumn(dataGrid, i); dataGrid.Columns.Add(templateColumn); } }
private static void OnColumnHeadersChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { var dataGrid = (DataGrid)d; dataGrid.AutoGenerateColumns = false; dataGrid.CanUserAddRows = false; dataGrid.CanUserDeleteRows = false; var headers = dataGrid.GetColumnHeadersSource(); if (headers == null) { return; } var count = headers.Count(); for (int i = 0; i < count; i++) { if (dataGrid.Columns.Count > i) { var column = (IndexColumn)dataGrid.Columns[i]; column.BindHeader(headers, i); } else { var templateColumn = new IndexColumn(dataGrid, headers, i); dataGrid.Columns.Add(templateColumn); } } }
private static void AddColumn(DataGrid dataGrid, int i) { if (dataGrid.Columns.Count > i) { var column = dataGrid.Columns[i] as IndexColumn; if (column == null) { throw new InvalidOperationException(); } } else { var templateColumn = new IndexColumn(dataGrid, i); dataGrid.Columns.Add(templateColumn); } }