mardi 6 janvier 2015

C# Listview DisplayMemberBinding shows "wrong" value

In my WPF app I have a Listview with a couple columns and one column with a checkbox inside.

The xaml is as follows:



<ListView x:Name="listviewImported">
<ListView.View>
<GridView>
<GridViewColumn Header="Check" Width="50">
<GridViewColumn.CellTemplate>
<DataTemplate>
/*This line may be the prob.*/ <CheckBox IsChecked="{Binding MarkedForCheck}" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Pos." Width="75" DisplayMemberBinding="{Binding PositionAsString}" />
<GridViewColumn Header="Value" Width="175" DisplayMemberBinding="{Binding ImportValue}" />
<GridViewColumn Header="Type" Width="175" DisplayMemberBinding="{Binding ImportValueTypeDescription}" />
</GridView>
</ListView.View>
</ListView>


The ItemSource is assigned like this:



listviewImported.ItemsSource = _catalog.ImportedList;


The ImportedList in the _catalog is of Type ImportedElem:



private List<ImportedElem> _importedList = new List<ImportedElem>();


This is the ImportedElem class:



public class ImportedElem : BaseElem {

public ImportedElem(int Position, string ImportValue) : base(Position, ImportValue) {
}

//MARKED FOR CHECK
public bool MarkedForCheck = true;
}


This is the problem:

When I add an ImportedElem to the List, then the Listview will update and the columns "Pos.", "Value" and "Type" contain the correct Data. However, the Column with the checkbox ("Check") always shows a nonchecked Checkbox after adding it to the List. The Data is correct, the column just shows the wrong Data. I can modify the checkbox in the list and it will update the Data, that is good. But the List should contain the correct Data right after adding the Element to the list, wich it is not doing.



It would be very interesting to know why 3 columns are correct and the checkbox doesn't work.





Aucun commentaire:

Enregistrer un commentaire