Refresh the value of a specific list item

I have a ListView :

 <ListView.View> <GridView> <GridViewColumn x: Name = "KeyColumn1" Header = "Key" Width = "100" DisplayMemberBinding = "{Binding Path=Label}"/ > <GridViewColumn x: Name = "ValueColumn1" Header = "Value" Width = "130" DisplayMemberBinding = "{Binding Path=Value}"/> </GridView> </ListView.View> 

Time is defined as: public DateTime time = DateTime.Now;

How can I update time in two different ways? I was able to get the time and display it in Ringing() , but the time is not updated in Established() .

 private void Ringing() { CallTabLv1.Items.Add(new { Label = "Time", Value = time.ToString() }); CallTabLv1.Items.Add(new { Label = "Call Type", Value = "Call in" }); } private void Established() { CallTabLv1.Items.Refresh(); } 

I know that the easiest way is to clear the elements and add them to Established() again, but since more than two elements need to be added, I do not want the code to look long and duplicated. Another way that I thought was to delete a specific row and then insert again, but this method is not suitable since my data is dynamic.

+4
source share
2 answers

The easiest way is to create an array / list with columns. Then go through the list and find your "key". Whether this key is the primary key or the key of your own design is up to you. I would advise you to use your own key and create your own class, otherwise you will create a mess later when all the lists have their (or several) p-keys.

 class Columns : MSColumnClass { String Name; // name of db column CCData value; // CCData contains int / long / String / Date } class row_data { std::list<Columns> *m_colum long row; long my_key; } 
0
source

Instead of using an anonymous type, create a type of type

  public class LabelValuePair:INotifyPropertyChanged { public bool RequiresTimeRefresh{get { return !string.IsNullOrEmpty(Label) && Label.ToLower() == "time"; }} private string label; public string Label { get { return label;} set { label = value; } } private string value; public string Value { get { return value; } set { this.value = value; Notify("Value");} } public LabelValuePair(string label, string value) { this.Label = label; this.Value = value; } private void Notify(string propName) { if(PropertyChanged!=null) PropertyChanged(this,new PropertyChangedEventArgs(propName)); } public event PropertyChangedEventHandler PropertyChanged; } 

Call method

  private void Ringing(DateTime time) { CallTabLv1.Items.Add(new LabelValuePair("Time", time.ToString())); CallTabLv1.Items.Add(new LabelValuePair("Call Type", "Call in")); } 

Installed Method

  private void Established() { foreach (LabelValuePair item in CallTabLv1.Items) { if (item.RequiresTimeRefresh) item.Value = DateTime.Now.ToString(); } } 

Now you don’t even need to call Refresh.NotifyPropertyChanged will do this.

0
source

All Articles