c# - WPF ListView won't update binded dictionary -


i bound dictionary listview in wpf.

<listview x:name="listview" horizontalalignment="left" height="100" margin="30,324,0,0" verticalalignment="top" width="270" itemssource="{binding archivedatadb}">     <listview.view>         <gridview>              <gridviewcolumn header="archive name"                         displaymemberbinding="{binding key}" />              <gridviewcolumn header="data db amount"                         displaymemberbinding="{binding value}" />         </gridview>     </listview.view> </listview> 

thats dictionary:

public dictionary<string, int> archivedatadb {         {         if(_archivedatadb == null)         {             _archivedatadb = new dictionary<string, int>();             _archivedatadb.add("master data", 0);         }         return _archivedatadb;     }     set     {         _archivedatadb = value;     } } 

i have button should string , int 2 textboxes , add these 2 information list

public void addentry(object args) {     archivedatadb.add(archivename, datadbamount);     onpropertychanged("archivedatadb"); } 

the onpropertychanged method gets implemented inotifypropertychanged interface.

protected void onpropertychanged(string name) {     propertychangedeventhandler handler = propertychanged;     if (handler != null)     {         handler(this, new propertychangedeventargs(name));     } } 

for testing purposes added messagebox.show addentry method , displayed entrys. i'm 100% sure new key , value gets added dictionary, listview not updated.

thanks help

max

to quick fix can use this:

replace

return _archivedatadb; 

with

return _archivedatadb.todictionary(x=>x.key, y=>y.value); 

and line

archivedatadb.add(archivename, datadbamount); 

withi line

_archivedatadb.add(archivename, datadbamount); 

when listview gets new instance of dictionary updates layout.

but make should use implementation od observabledictionary or use other observable collection.

for example here :

.net observabledictionary

i hope helps.


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -