Frage

The problem is, when I edit programmatically column values in datagrid and scroll down, those values repeat in next cells of column which become visible. This seems like virtualization bug or "effect" since when I switch it off, problem disappears. I think the problem is in this place:

public void EditedCell(object oItem, string oColumnName, ref List<string> lErrors, object newValue = null)
{
    DataGridRow dgRow = dgDati.ItemContainerGenerator.ContainerFromItem(oItem) as DataGridRow;
    /* In other places, when I call EditedCell(DataGridRow, ...) it works fine.
       The problem shows up only when I call EditedCell(object oItem, ...) */
    EditedCell(dgRow, oColumnName, ref lErrors, newValue);
}

This is the screen of problem. Yellow cells are programmatically changed and other 0000 containing cells are shown due to this problem. When I read data from DataSource it doesnt have those 0000 values in DataRows:

enter image description here

Also to set value of cell, I set cell controls in cell and DataRow value to change value and display it properly:

if (oElement.GetType() == typeof(TextBox))
{
    (oElement as TextBox).Text = newValue.ToString();
}

if (oElement.GetType() == typeof(TextBlock))
{
    (oElement as TextBlock).Text = newValue.ToString();
}

Have anyone seen anything similar and knows how to deal with that?

War es hilfreich?

Lösung

Don't manipulate WPF control's through procedural code. This is not the WPF way. In WPF you should manipulate your data which is binded to the UI, instead of manipulating the UI directly. This design pattern is known as MVVM and will spare you all this headache.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top