user742102
user742102

Reputation: 1365

Listview does not change upon update

I have a listview with observable collection source. I am sure the data changed in code behind but I am totally exhausted why the UI won't display the changes. What am I missing?

My xaml:

<GridViewColumn Width="70" Header="Status">
    <GridViewColumn.CellTemplate>
        <DataTemplate>
            <!--<CheckBox IsChecked="{Binding Path=Status, Mode= Twoway}" HorizontalContentAlignment="Center" IsEnabled="False"/>-->
            <TextBlock Text="{Binding Path=Status, Mode= Twoway}" TextAlignment="Center" Loaded="Page_Loaded"/>
        </DataTemplate>
    </GridViewColumn.CellTemplate>
</GridViewColumn>

My class:

public partial class tblADRMaster: INotifyPropertyChanged
{
    public string Status
    {
        get { return _status; }
        set
        {
            if (_status != value)
            {
                _status = value;
                OnPropertyChanged("Status");
            }
        }
    }
}

This is my code behind:

ObservableCollection<tblADRMaster> list = new ObservableCollection<tblADRMaster>();
CurrentCase = FileMaintenanceBusiness.Instance.GetADRMasterInfobyKeywordRefresh(caseNo.CaseIDSystem, "CaseIDSystem");
foreach (var c in listFrWWC)
{
    if (c.CaseIDSystem != CurrentCase.CaseIDSystem)
        list.Add(c);
    else
        list.Add(CurrentCase);

}
foreach (var caseMaster in list)
{
    caseMaster.IsMissingDocs = GetMissingDoc(caseMaster.tblADRDispositions);
    caseMaster.IsProblemCase = !string.IsNullOrEmpty(caseMaster.ProblemNote) ? "Yes" : "No";
    caseMaster.Status = GetStatus(caseMaster);
}

lvAdrMaster.ItemsSource = list;

I want to change the status. It does change coz I placed a breakpoint and STATUS went from HOLD to ACTIVE but the listview won't display the change. it remains HOLD, unless I press back btn or reload the items.

I have been troubleshooting this all day and I cannot seem to think of anything else I could have missed. Pls tell me. thanks.

Upvotes: 2

Views: 1856

Answers (3)

Vinit Sankhe
Vinit Sankhe

Reputation: 19885

Have you implemented INotifyPropertyChanged interface in tblADRMaster class and raised property notification for Status property?

Upvotes: 0

Learner
Learner

Reputation: 1542

Try to use CollecitonViewSource

 private ListCollectionView EmpCollectionView
    {
        get
        {
            return (ListCollectionView)CollectionViewSource.GetDefaultView(ListOfEmp);
        }
    }


    private ObservableCollection<Employee> listOfEmp = new ObservableCollection<Employee>();
    public ObservableCollection<Employee> ListOfEmp
    {
        get { return listOfEmp; }
        set { listOfEmp = value; }
    }

and after u update the collection just refresh the collectionViewSource like

 public void OnAdd(object sender)
    {
        ToggleButton tb = sender as ToggleButton;

        EmpCollectionView.SortDescriptions.Clear();
        if (tb.IsChecked == true)
        {

            EmpCollectionView.SortDescriptions.Add(new SortDescription(tb.Content.ToString(), ListSortDirection.Ascending));
            EmpCollectionView.Refresh();
        }
        else
        {
            EmpCollectionView.SortDescriptions.Add(new SortDescription(tb.Content.ToString(), ListSortDirection.Descending));
            EmpCollectionView.Refresh();
        }
    }

Upvotes: 1

d.moncada
d.moncada

Reputation: 17402

Try this for your textblock binding:

Text="{Binding Path=Status, Mode= Twoway, UpdateSourceTrigger=PropertyChanged}"

Upvotes: 1

Related Questions