Add A Value to Rows And Cells In WPF -


i developing program datagridview. need adding values rows , cells:

my code:

  (int = 0; < 0x18; i++)             {                 this.dataview1.updatedefaultstyle();                this.dataview1.rows[i].cells[0].value = i;                 this._dataview1[i].cells[1].value = getname(i);                 application.doevents();             } 

it dont work error:system.windows.controls.datagrid not contain rows. same error cells. works fine in c#. wpf code;

<grid background="#ffe5e5e5">     <datagrid x:name="dataview1" horizontalalignment="left" verticalalignment="top" height="337" width="809">         <datagrid.columns>             <datagridtextcolumn binding="{x:null}" clipboardcontentbinding="{x:null}" header="client"/>             <datagridtextcolumn binding="{x:null}" clipboardcontentbinding="{x:null}" header="name"/>         </datagrid.columns>     </datagrid> 

please me! hope made clear enough.

try . wpf has magic bindings

you need add item collection(your source) wpf bindings , datagrid add rows you

<datagrid itemssource="{binding customers}" autogeneratecolumns="false" > <datagrid.columns>       <datagridtextcolumn header="client" binding="{binding client}" />       <datagridtextcolumn header="name" binding="{binding name}" />  </datagrid.columns> </datagrid> 

the viewmodel/codebehind

public class myclients  {  public string name { get; set; }        public string client{ get; set; }  }  observablecollection<myclients>  customers=new observablecollection<myclients>();  // add data customer collection , observable collection notify when add/remove item in ob. collection 

**on add portion **

       (int = 0; < 0x18; i++)         {             customers.add(new myclients(){client="value",name="value"});         }  **collection updated datagrid updated** 

see reference link1

link2

link 3


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -