wpf - DataGrid don't update after changing the ItemsSource -
i have info grid binded observablecollection object. on event, clear observablecollection , add together new items it. when finished, seek update datagrid, still shows old rows. doing wrong? xaml:
<datagrid itemssource="{binding }" autogeneratecolumns="false" name="dgvcurrentfaults" tabindex="0" background="transparent" rowbackground="#b4cdcd" foreground="#314e54" > <datagrid.columns> <datagridtemplatecolumn header="icon" width="70" isreadonly="true"> <datagridtemplatecolumn.celltemplate> <datatemplate> <image source="{binding icon}" width="20" height="20"/> </datatemplate> </datagridtemplatecolumn.celltemplate> </datagridtemplatecolumn> <datagridhyperlinkcolumn header="display" binding="{binding display}" contentbinding="{binding display}" isreadonly="true"> <datagridhyperlinkcolumn.elementstyle> <style> <eventsetter event="hyperlink.click" handler="dgvcurrentfaults_cellcontentclick"/> </style> </datagridhyperlinkcolumn.elementstyle> </datagridhyperlinkcolumn> <datagridtextcolumn header="fault name" binding="{binding falut_name}" width="150" isreadonly="true"> <datagridtextcolumn.elementstyle> <style targettype="textblock"> <setter property="textwrapping" value="wrap"/> </style> </datagridtextcolumn.elementstyle> </datagridtextcolumn> <datagridtextcolumn header="description" binding="{binding fault_description}" width="240" isreadonly="true"> <datagridtextcolumn.elementstyle> <style targettype="textblock"> <setter property="textwrapping" value="wrap"/> </style> </datagridtextcolumn.elementstyle> </datagridtextcolumn> <datagridtextcolumn header="action required" binding="{binding actionrequired}" width="200" isreadonly="true"> <datagridtextcolumn.elementstyle> <style targettype="textblock"> <setter property="textwrapping" value="wrap"/> </style> </datagridtextcolumn.elementstyle> </datagridtextcolumn> <datagridtextcolumn header="id fault" binding="{binding idfault}" visibility="hidden" isreadonly="true"/> </datagrid.columns> </datagrid> and code
public observablecollection<faultsinfo> infofaultlist { get; set; } private void updatetable() { infofaultlist.clear(); infofaultlist.add(new infofault(1)); infofaultlist.add(new infofault(2)); dgvcurrentfaults.itemssource = null; dgvcurrentfaults.itemssource = infofaultlist; dgvcurrentfaults.updatelayout(); dgvcurrentfaults.items.refresh(); } edit:
after having many more looks on subject, see first time update datagrid on loaded event of usercontrol. in case, datagrid update fine. later, datagrid updates on event launched communication. in case, dose not udate. thought maybe problem seek update thread, although utilize invoke.
i source property observable collection, doesn't need set again. doesn't need code:
dgvcurrentfaults.itemssource = null; dgvcurrentfaults.itemssource = infofaultlist; also, code above doesn't works because class must implement inotifypropertychanged interface:
observablecollection<faultsinfo> _infofaultlist; public observablecollection<faultsinfo> infofaultlist { { homecoming _infofaultlist; } set { _infofaultlist = value; notifypropertychanged("infofaultlist"); } } also need check if binding working. if xaml code right, info grid's info context should collection before binding working using it: itemssource="{binding }". if collection not info context, should prepare binding , create 1 itemssource="{binding infofaultlist}".
hope helps.
wpf datagrid itemssource
No comments:
Post a Comment