Hello,
I have a XamDataGrid that binds to an object that have only a private constructor. So I had to create my own add new record button. Since I over wrote the add button already implemented in grid, I'm not getting focus on the new record.
1) How can I put the focus on the new added record. Please note that I'm using MVVM pattern.
2) I have set AddNewRecordLocation="OnTop" but the record is getting added on the button.
I'm wondering if someone looking into my question.
Thank you
Can you send a small sample project demonstrating the issue you are having? It's unclear exactly what the issue is. If all you want is to set to activate the first record in the grid you can set the IsActive property on the record.
this.xamDataGrid1.Records[0].IsActive = true;
Hi Michael,
Attached is a sample project that resemble what I'm trying to do. The constructors have to stay private and called through a public factory method.
1) If you click on the add button the focus is not getting set on the newly created record.
2) AddNewRecordLocation="OnTop" but the new record is added to the bottom.
Did you have a chance to a look at the attached project ?
Yes I have. The fact that there is no add new row at the top of your data grid concerns me. I attempted to reproduce this with my own sample and I was not able to. Please see my attached sample below to test how the add new record appears at the top.
Keep in mind that adding records via your command will not make them appear at top of your grid automatically by setting the AddNewRecordLocation property. In order to programmatically add new records at the top you must set the index to zero for each new record added and update the rest of your record's index. The grid loads the records as they appear in your data. So if you are not adding the new records as the first item in your collection they will not appear at the top.
Let me know if you have any questions.
As I specified in my original specs that I have a private constructor. This will make the plus sign on the xamdatagrid disappear. I can't make the constructor public due to design restrictions. I need to add a new record via a button (forget the Top requirement). How can I automatically focus on the New record using MVVM.
***Another issue with this xamdatagrid is that when you a new record with the add bottom and fill one cell or more and the delete key on the key board does not work anymore on the grid.
Hey Michael,
Did you check the behaviour of the xamdatagrid in the sample project I have submitted ? It is important that we resolve these issues ASAP.
The xamdatagrid is behaving strangely on the delete action as well.
Please address all issues I have pointed in my previous post.
The simplest way to get the add new row focus is to handle the grid's InitializeTemplateAddRecord event and force the first cell in the row into edit mode.
eg.
private void XamDataGrid1_InitializeTemplateAddRecord(object sender, Infragistics.Windows.DataPresenter.Events.InitializeTemplateAddRecordEventArgs e) { var addRecord = e.TemplateAddRecord;
Dispatcher.BeginInvoke(new Action(() => { CellValuePresenter.FromCell(addRecord.Cells[0]).Editor.StartEditMode(); }), DispatcherPriority.Background, null); }
Keep in mind this only works if the row is in view. I am continuing to inject this into your sample. Let me know if this suites your requirements or have any additional questions.
Michael,
The code provided does not compile. Please added to the sample project I have provided.
You haven't addressed the delete issue.
User101 said: Michael, The code provided does not compile. Please added to the sample project I have provided. You haven't addressed the delete issue.
The BeginInvoke is not a static method. It need an instance of the object to reference it.
I found the issue with the weird behavior of the delete. I had UpdateMode="OnUpdate". Once I took it out, the delete worked fine.