BUG DataGrid repeats cells along columns after a scroll down and up

Jan 27, 2010 at 8:10 PM
Edited Jan 28, 2010 at 11:35 AM


I have a DataTable as a itemsource of a datagrid.

I'm creating datatemplatecolumns dinamically, In these datatemplatecolumns I have a customized usercontrol, there is some rows that do not have to show my customized user control. The datagrid displays well, however after a scroll down and up I can see that cells are repeating along columns, when I reorder a column the cells refresh and the datagrid displays well again.

Do you know something I can do??? this problem is making me crazy

here you are my code for generate templates dinamically:

private void buildScoringTemplates(ScoringSettings scoringSettings)
            foreach (Risk.Structures.ScoringMetric item in scoringSettings.ScoringMetrics)
                Binding itemsBinding = new Binding();
                itemsBinding.Path = new PropertyPath("sm-" + item.Id);
                FrameworkElementFactory scoreFactory = new FrameworkElementFactory(typeof(ScoreControl));
                scoreFactory.Name = "score";
                scoreFactory.SetBinding(ScoreControl.ItemsProperty, itemsBinding);                 
                DataTemplate itemsTemplate = new DataTemplate();
                itemsTemplate.VisualTree = scoreFactory;
                this.Resources.Add("sm-" + item.Id, itemsTemplate);

In the autogenerating columns event I assign my dinamyc templates in the column
 private void dataGrid1_AutoGeneratingColumn(object sender, Microsoft.Windows.Controls.DataGridAutoGeneratingColumnEventArgs e)
                     string id = e.PropertyName.Substring(2);
                    e.Column.Header = Scorings[Convert.ToInt32(id)];
                    DataGridTemplateColumn customColumn = new DataGridTemplateColumn();
                    customColumn.Header = Scorings[Convert.ToInt32(id)];
                    customColumn.CellTemplate = (DataTemplate)Resources["sm-"+id];
                    e.Column = customColumn;