Hi there
We got a problem with the AddNewRecord funtionality of the xamDataGrid.
On some cells, we're showing a button to the user. When the user clicks the button, another window is shown with whatever content. Then the user can select an option in this window, and the value is getting written back to the underlying dataitem. Everything is working fine on a record, where the underlying dataitem is already there. But when the user is in the AddNew-Row, and he starts typing or directly clicks the button, in this specific cell with the button, the xamDataGrid is not instanciating a new underlying dataitem. Therefore, our application does not work as expected.
I have created a small sample application, where you can exactly see, what our problem is.
The underlying dataitem 'Entry' has 3 properties. 'Age', 'LastName' and 'Name'. On 'Age' and 'LastName' everything is working as expected. But on 'Name' (where i have attached the Style for the CellValuePresenter), the constructor is not getting called, when the user starts typing or is clicking the button.
Can you help me with that? We need the same behavior, which a cell has without that style when a user starts typing. Also the same behavior, when the user clicks the button, as he would start typing.
Hi Christian,
The Entry class is being instantiated when the cell editor value changes. There is a specific editor type (ValueEditor) that the cell is looking for and currently your CellValuePresenter style template doesn't have this editor. So the simplest thing you could do is add the appropriate ContentPresenter with the correct x:Name so that the cell can find it and insert the desired ValueEditor. Replace your TextBox with this:
<ContentPresenter x:Name="PART_EditorSite" Grid.Row="0" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Margin="{TemplateBinding Padding}" Style="{TemplateBinding ForegroundStyle}"/>
You can still have all the other custom stuff inside the CellValuePresenter template, but our code is specifically looking for a PART_EditorSite so it can insert a ValueEditor (XamTextEditor, XamNumericEditor, etc).
This should give you the same behavior as the other cells that don't have any styling.
Ok, figured out, how to make it work with our described value box. I exchanged the internally used TextBox with a xamTextEditor. Then everything is working fine, when a user starts typing. Check the updated, attached sample.
But, now i'm stuck with the button. How to raise the 'EditModeStartingEvent' which i found in the abstract class Infragistics.Windows.Editors.ValueEditor? Or something similiar to put the cell in EditMode when the user clicks the button instead of starting typing...
Wow, looks like you made a lot of progress on your sample. Awesome!
For the button, what is supposed to happen in your application when it is clicked? If all it is supposed to do is start edit mode then you can use the XamDataGrid.ExecuteCommand method in order to start edit mode. One of the commands you can execute is called StartEditMode. You can find a list of the commands here. It should work for your needs since when you click in that cell it should become the ActiveCell which then the StartEditMode command can apply to.
This alone won't trigger the Entity to get created I don't think. I believe the editor value actually needs to change so when you click on the button you would need to get the ValueEditor's Value and change it to something in order to trigger the Entity to be created.
Thank you for your help. But as we moved forward with our application, we experienced another issue. We have now a validation system implemented which is working with the interface IDataError. And the grid does support this very nicely. But as soon we use any CellValuePresenter style, the Cell is not painted red anymore.
Can you help me with this?
Kind regards
I'm glad you were able to come up with a solution! Let me know if you have any further questions.
Hi Rob
Thank you. But i had to make progress, because this little thing was quite a showstopper for us. ;)
Yes, i knew the XamDataGrid.ExecuteCommand() method and tried to use it. But to start the EditMode did not trigger the creation of the new entity (as you was expecting).
I solved it with a command, which we execute now before we execute our command which shows the additional window. The command does following:
- When the ActiveCell is in a Record which has the property IsAddRecord == true and the property DataItem is null. Then i getting the CellValuePresenter instance with CellValuePresenter.FromCell().
- Then i call the StartEditMode() of this CellValuePresenter
- Then i put a datatype-matching value in Editor.Value
- Then i call EndEditMode(true, true) of this CellValuePresenter (after this, the new entity is created).
Afterwards i call StartEditMode(), set the Value of the Editor to null again, and call EndEditMode(true, true)
And so it is working. :)
I could not just push the value to the ActiveCell.Value, because this did not trigger the creation of the new entity (even the value was shown in the UI).
Regards
Chris