Click here to Skip to main content
15,886,783 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm having two classes Cricket, Football and List of Observable collections of type object. Based on certain condition I want to add the object of type Cricket/Football to Observable Collection. I'm not assigning any data i.e just creating and instance of class Cricket/Football and adding that instance to Observable Collections and binding to UI. My expectation is, as I'm not assigning any data to the instance of Cricket/Football, only header has to create in the datagrid. But what I found was a row with the default value of the variables defined under the respective class along with the row header as I'm creating the instance of that class. How shall I avoid creating void row where my datagrid header is unaffected. 


HTML
<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" />


What I have tried:

I googled for the above mentioned problem and all I was found is to set CanUserAddRows property to false
Posted
Updated 25-Jul-16 4:14am
v2
Comments
partha143 25-Jul-16 10:12am    
My Model :
<pre lang="c#">
public class Cricket : INotifyPropertyChanged
{
private string batsmen;
private int scorecore;

public string Batsmen
{
get { return batsmen; }
set
{
batsmen = value;
OnPropertyChanged("Batsmen");
}
}

public int Scorecore
{
get { return scorecore; }
set
{
scorecore = value;
OnPropertyChanged("Scorecore");
}
}
}
</pre>

my View Model :
<pre lang="c#">
Cricket cricket = new Cricket();
MyList.Add(cricket);

ObservableCollection<object> myList;
public ObservableCollection<object> MyList
{
get { return myList; }
set
{
myList = value;
OnPropertyChanged("MyList");
}
}
</pre>
MayurDighe 26-Jul-16 14:04pm    
Dear parth143,

Please use "Improve question" widget to provide additional information in question itself.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900