When my datagrid loads, the newrow row is not showing. It only shows after I click on one of the headers. After that it works fine, and correctly adds new records. I'm using the express 2008.2 version. Here's my current code:
<igDP:XamDataGrid.FieldLayoutSettings>
<igDP:FieldLayoutSettings AllowAddNew="True" AllowDelete="True" SummaryDescriptionVisibility="Collapsed" AutoGenerateFields="False" HighlightAlternateRecords="True" GroupBySummaryDisplayMode="Default" AddNewRecordLocation="OnBottom" />
</igDP:XamDataGrid.FieldLayoutSettings>
@Kevin,
Can you clarify what you are asking?
@All
For those of you looking for a quick solution for showing the Add New Record. This simple ViewModel with a empty constructor in the PersonName data item is all you need even if one exists already.
eg.
public MainWindow() { InitializeComponent(); //Bind to the datagrid. this.xdg1.DataSource = new NameList(); }
public class NameList : ObservableCollection<PersonName> { public NameList() : base() { Add(new PersonName("Willa", "Cather")); Add(new PersonName("Isak", "Dinesen")); Add(new PersonName("Victor", "Hugo")); Add(new PersonName("Jules", "Verne")); } }
public class PersonName : INotifyPropertyChanged { private string firstName; private string lastName;
public PersonName(string first, string last) { this.firstName = first; this.lastName = last; }
public PersonName() { }
public string FirstName { get { return firstName; } set { firstName = value; OnPropertyChanged("FirstName"); } }
public string LastName { get { return lastName; } set { lastName = value; OnPropertyChanged("LastName"); } }
public event PropertyChangedEventHandler PropertyChanged; protected void OnPropertyChanged(string name) { PropertyChangedEventHandler handler = PropertyChanged; if (handler != null) { handler(this, new PropertyChangedEventArgs(name)); } } }
If this is true, then how is dependency injection used? Doesn't having to use a concrete instance defeat the entire reason for having mocks?
Hello Rajib,
The behavior is expected, because the data object should have an empty constructor and in your case the data object is an interface, and the interfaces doesn't have constructors.
The issue is AllowAddNew (+) is not appearing. I am binding the grid to an Observable Collection<IProduct> where IProduct is an interface. Based on few responses from this forum, I converted ObservationCollection to BindingList
ProductsBinding = new BindingList<IProduct>(Products) {AllowNew = true};
It does shows up the + sign and an empty row, but when I start adding, it throws the following exception :
Constructor on type IProduct' not found.
Is it possible to make ObservableCollection working for add new row in DataGrid?
-Vivek