When I click the AddRecord row, I want to create a new DataItem for that record, and set some default values... then I want to automaticlly start edit mode.. how can I accomplish this?
You can also do that in the Loaded event of the XamDataGrid, but the Default values of the Add Record will be visible at all times (you have to this is in RecordUpdated event to make the values reappear after the adding)
private void xamDataGrid1_Loaded(object sender, RoutedEventArgs e) { DataRecord r = xamDataGrid1.RecordManager.CurrentAddRecord as DataRecord; Person p = new Person(); r.Cells[0].Value = p.Name; r.Cells[1].Value = p.Email; r.Cells[2].Value = p.Department; r.Cells[3].Value = p.Salary; }
Alex.
Hello,
Well, this is not supported. I think it is because the constructor of the Class ( the DataSource ) is called when you start typing/entering data into one of the cells -- RecordAdding event is fired after entering at least one character of data. But there is a workaround -- you can handle the EditModeStarting event like this: ( Person is my class -- the underlying DataSource ) :
private void xamDataGrid1_EditModeStarted(object sender, Infragistics.Windows.DataPresenter.Events.EditModeStartedEventArgs e) { if (e.Cell.Value == null) { DataRecord r = xamDataGrid1.RecordManager.CurrentAddRecord as DataRecord; Person p = new Person(); r.Cells[0].Value = p.Name; r.Cells[1].Value = p.Email; r.Cells[2].Value = p.Department; r.Cells[3].Value = p.Salary; } }
Tell me if this works in your scenario?
No really. I want the default values to appear when the user clicks the AddRecord, not when he starts typing/editing a cell.. that's 'too late' in my case.
I believe this is the same issue here