wpf - avoid creating empty row in datagrid -


i'm having 2 classes cricket, football , list of observable collections of type object. based on condition want add object of type cricket/football observable collection. i'm not assigning data i.e creating , instance of class cricket/football , adding instance observable collections , binding ui. expectation is, i'm not assigning data instance of cricket/football, header has create in datagrid. found row default value of variables defined under respective class along row header i'm creating instance of class. how shall avoid creating void row datagrid header unaffected.

<datagrid selectionmode="single" verticalalignment="stretch" itemssource="{binding itemsource, updatesourcetrigger=propertychanged}"  canuserreordercolumns="false" canuseraddrows="false" isreadonly="true" canuserdeleterows="false" canuserresizecolumns="false" horizontalgridlinesbrush="black" verticalgridlinesbrush="black" horizontalscrollbarvisibility="disabled" verticalscrollbarvisibility="disabled" /> 

edit

i think datagrid's canuseraddrows property set true. set false fix issue.

canuseraddrows="false" isreadonly="true" 

edit : sorry. read question right now. it’s because observablecollection’s type object. show small sample understand how binding works in datagrid. collection should have public properties, datagrid bind columns it. if use collection type of object have no properies binding, empty rows displayed.

xaml :.

<datagrid autogeneratecolumns="false" height="253" horizontalalignment="left" margin="27,24,0,0" name="datagrid1" verticalalignment="top" width="448">             <datagrid.columns>                 <datagridtextcolumn header="first" binding="{binding path=field, mode=twoway, updatesourcetrigger=propertychanged}" />             </datagrid.columns>  </datagrid> 

code behind :

public partial class mainwindow : window  {      public observablecollection datasource;     public mainwindow()     {         initializecomponent();          this.datasource = new observablecollection<somedatasource>();          this.datasource.add(new somedatasource { field = "123" });         this.datasource.add(new somedatasource { field = "1234" });         this.datasource.add(new somedatasource { field = "12345" });          this.datagrid1.itemssource = this.datasource;     } }  public class somedatasource {     public string field {get;set;} } 

Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -