c# - List View With ObservableCollection Not Updating While Adding Or Deleting Records -


my listview not updating while adding or deleting items. moreover, when close , re-open form, updated list comes up. here c# code:

using library; using mysql.data.mysqlclient; using system; using system.collections.generic; using system.collections.objectmodel; using system.collections.specialized;  namespace bajaj.viewmodels {     #region records...     public class _rec_ledgergroup     {         public int sno { get; set; }         public int id { get; set; }         public string name { get; set; }         public string alias { get; set; }          public _rec_ledgergroup(int sno, int id, string name, string alias)         {             this.sno = sno;             this.id = id;             this.name = name;             this.alias = alias;         }     }     #endregion      public class grouplistvm : observablecollection<_rec_ledgergroup>     {         public grouplistvm()             : base()         {             collectionchanged += grouplistvm_collectionchanged;              database db = new database();             db.open();             try             {                 mysqlcommand command = db.connection.createcommand();                 command.commandtext = "select * ledgergroups order id;";                 mysqldatareader rdr = command.executereader();                 if (rdr.hasrows)                 {                     list<_rec_ledgergroup> rc = new list<_rec_ledgergroup>();                     int count = 0;                     while (rdr.read())                     {                         count++;                         add(                             new _rec_ledgergroup(                                 count,                                 convert.toint32(rdr["id"]),                                 rdr["name"].tostring(),                                 rdr["alias"].tostring()                                 ));                     }                      rdr.close();                     db.close();                 }                 else { db.close(); }             }             catch { db.close(); }         }          private void grouplistvm_collectionchanged(object sender, notifycollectionchangedeventargs e)         {          }     } } 

here xaml:

<listview              x:name="grouplist"              grid.columnspan="2" grid.row="5"              background="#ffeeeeee" margin="0,2" fontsize="12"              itemssource="{binding source={staticresource grouplistcollection}}">             <listview.view>                 <gridview>                     <gridviewcolumn header="sno" width="100" displaymemberbinding="{binding sno}" />                     <gridviewcolumn header="id" width="100" displaymemberbinding="{binding id}" />                     <gridviewcolumn header="name" width="200" displaymemberbinding="{binding name}" />                     <gridviewcolumn header="alias" width="100" displaymemberbinding="{binding alias}" />                 </gridview>             </listview.view>         </listview> 

i don't know getting wrong.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -