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>
Hello,
It is really odd that it does not work correctly ( especially with ObservableCollections ) and probably it is due to the way of binding. I have attached project with simple binding. Please take a look at it and notify us if this solution can be of some help to you.
I tried your sample. The first time when I load the window, nothing shows up. Once I click on the button, the data is available and everything works fine.
What my requirement is that I need to show up a blank grid (with an empty bindinglist object) with the Add New Row, so that the user can start adding records to the grid. I am facing problem that in such scenarios, the grid is blank without the Add New Row.
Any suggestions will be appreciated.
I suggest using collections that implement IEditableCollectionView Interface. Here is an article about them: http://msdn.microsoft.com/en-us/library/system.componentmodel.ieditablecollectionview.aspx
and
http://blogs.msdn.com/vinsibal/archive/2008/05/20/wpf-3-5-sp1-feature-ieditablecollectionview.aspx
Using that I think there should be no problem in showing a blank grid with the AddNewRow indicator visible.
Alex.
I tried the collections that implement that interface (as in the code snippet below), but still have the same problem.
WorkingList1 = new BindingList<DeleteableChar>();WorkingList2 = new BindingListCollectionView(new BindingList<DeleteableChar>());WorkingList3 = new ListCollectionView(new List<DeleteableChar>());
I have attached a sample with three grids bound to three different collection types. When loaded, none of the AddNew rows are visible. If you resize the window though, the AddNew rows then show up.
Alex/Infragistics, are you able to reproduce the problem with the samples uploaded?
Hi,
We reproduced the situation but cannot determine whether this is incorrect behavior or is just missed scenario. I can offer you a workaround or you can submit it as a request.
The workaround is :
1) remove from the grid:
AllowAddNew="True" AddNewRecordLocation="OnTopFixed"
2) Add a blank dummy element in the collection:
WorkingList1.Add(new DeleteableChar());
3) Handle the RecordUpdated event like this:
private void CharacteristicsGrid_RecordUpdated(object sender, Infragistics.Windows.DataPresenter.Events.RecordUpdatedEventArgs e) { CharacteristicsGrid.FieldLayoutSettings.AllowAddNew = true; CharacteristicsGrid.FieldLayoutSettings.AddNewRecordLocation = Infragistics.Windows.DataPresenter.AddNewRecordLocation.OnTopFixed; }
Hope this helps and is appropriate in your scenario,
@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