c# 3.0 - insert a data to particular cell in a wpf datagrid in c# -


hi new wpf datagrid. don't know how insert data in particular cell in row of wpf datagrid.

in normal windows form application can achieve binding list datagridview

datagridview.columns["username"].datapropertyname = "username"; datagridview.columns["role"].datapropertyname = "role";   bindingsource bs = new bindingsource();  bs.datasource = userlist;  datagridview.datasource = bs;  for(int i=0; i<userlist.count; i++) {    datagridview.rows[i].cells["company"].value = "default"; } 

now want achieve same in wpf datagrid can 1 provide sample code. sorry bad english , in advance.

first need class containing various properties want displayed. assume, since have userlist, class user (and implements inotifypropertychanged), , userlist list containing data.

first, if want add new users userlist, , make datagrid update, userlist variable needs of type observablecollection.

then, in xaml, bind userlist datagrid. there lot's of information on how this, simplest way set datacontext class containing userlist, , have datagrid follows:

<datagrid itemsource="{binding userlist}"/> 

then, change values, edit property of user, not grid.

for(int i=0; i< userlist.count; i++) {    userlist[i].company = "default"; } 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -