c# - update cell in datagrid wpf -


i have invoice program keeps track of items selected customer may want buy. every time "add item" button pushed, qty cell increments. problem im running in value getting upgraded in background, not being changed in cell itself. if click on cell however, value update. want update click "add item" button. can update cell information click button? code have works button push

public partial class mainwindow : window } private void btnadditem_click(object sender, routedeventargs e)     {         adddatagridrow(invoiceitemid, cbxitems.selecteditem.tostring(), convert.todouble(txtprice.text));     }      private void adddatagridrow(int id, string itemname, double itemprice)     {         //lstdataitem.add(new dataitem { sqty = count.tostring(), sname = itemname, sprice = itemprice, sremove = "delete item" });        // rows = new observablecollection<dataitem> { new dataitem () };         (int = 0; < rows.count; i++)         {             if (rows[i].sname == itemname)             {                 rows[i].sqty = rows[i].sqty + 1;                 id = rows[i].id;                 bsameitem = true;             }         }         if (id == 0)         {             rows.add(new dataitem());         }         else if (!bsameitem)         {             rows.add(new dataitem());         }           if (!bsameitem)         {             rows[id].id = id;             rows[id].sqty = 1;             rows[id].sname = itemname;             rows[id].sprice = itemprice;             invoiceitemid++;             dginvoice.itemssource = rows;          }         bsameitem = false;     } }  public class dataitem {     public int id { get; set; }     public int sqty { get; set; }     public string sname { get; set; }     public double sprice { get; set; } } 

i dont know if need xaml here in case

        <datagrid x:name="dginvoice" horizontalalignment="left" margin="10,92,0,0" verticalalignment="top" height="608" width="488" autogeneratecolumns="false" itemssource="{binding}" rowheight="25">             <datagrid.columns>                 <datagridtextcolumn header="qty" binding="{binding path=sqty}" width="100"/>                 <datagridtextcolumn header="name" binding="{binding path=sname}" width="200"/>                 <datagridtextcolumn header="price" binding="{binding path=sprice}" width="80"/>                 <datagridtemplatecolumn width="100">                     <datagridtemplatecolumn.celleditingtemplate>                         <datatemplate>                             <button height="20">delete item</button>                         </datatemplate>                     </datagridtemplatecolumn.celleditingtemplate>                 </datagridtemplatecolumn>             </datagrid.columns>         </datagrid> 

there not many responses wpf have seen when have searched topic. appreciated.

you have implement inotifypropertychanged interface on class dataitem changes in property gets reflected on ui.

public class dataitem : inotifypropertychanged {    public event propertychangedeventhandler propertychanged;     private int id;    public int id    {       { return id; }       set       {          if(id != value)          {             id= value;             onpropertychanged("id");          }       }    }    // create onpropertychanged method raise event    protected void onpropertychanged(string name)   {      propertychangedeventhandler handler = propertychanged;      if (handler != null)      {         handler(this, new propertychangedeventargs(name));      }   } } 

make other properties follow same syntax above id , see update in property value reflect on gui.


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -