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?
Hello,
I believe this is the same issue here
Alex.
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.
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?
Almost.. I use ComboEditors in my grid, and I -need- to select a value other than the default value in order to create a new dataitem in the list :( but this is for another day... thanks for your assistance :) any other tips regarding this issue are welcome.
I looked through the callstack of Infragistics code when the DataItem does get created and found the code path that needs to be followed.
If you find the editor for the first cell - the editor has to be in edit mode otherwise it doesn't follow the same code path. Here's an example. In my situation when a user does a key combination to copy data from a field in the last entered add row (lastAddedRecord - DataRecord) into a field in the new add row (this.ActiveCell)
//this is the XamDataGrid
if (this.ActiveCell.Record.DataItem == null) { CellValuePresenter cvp = CellValuePresenter.FromCell(this.ActiveCell); if (cvp.Editor != null) { this.ActiveCell.Record.DataPresenter.ExecuteCommand(DataPresenterCommands.StartEditMode); ValueEditor editor = cvp.Editor as ValueEditor; editor.Value = this.lastAddedRecord.Cells[this.ActiveCell.Field].Value; }}else { this.ActiveCell.Value = this.lastAddedRecord.Cells[this.ActiveCell.Field].Value;}
I have the same problem. The user can initiate some values into the add row. The problem is the Add record's DataItem is null. Is there a convenient way to for the creation of the object?
See attachment.
Right now it amost does what I want. What I want is that when the default values are set the underlying dataitem is also created, as in the changed values are commited to the datasource. When edit one of the values this does happen. Can I do this in code?
I experimented a bit with adding dataitems to the bound BindingList. This sort of works, but has side effects.. (for instance, I need to change the activerecord with a command)
Hope this helps.
Hi,
In this case send me a sceenshot or better a sample solution to be of further assistance