Hello. I'm having a strange problem where I can't seem to undo the value in a check box field. The field is of type boolean. I'm not sure if this is a xamDataGrid thing or something else. I'm using MVVM and this is what I have:
<xamdatagrid DataSource="{Binding Data, Mode=TwoWay}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="CellChanged"> <command:EventToCommand Command="{Binding OnCellChangedCommand}" PassEventArgsToCommand="True" /> </i:EventTrigger> </i:Interaction.Triggers>
</xamdatagrid>
private void OnCellChanged(CellChangedEventArgs e) {
var createEvent = (bool)e.Editor.Value;
if(createEvent){//if the new value is true
if(some logic){ e.Cell.Value = false }
}
So looking at the first if statement. If the user checks an unchecked checkbox in a cell, I check whether he can in fact check that check box. If not, I want the checkbox to return to an unchecked state.
The statement "e.Cell.Value = false" does not seem to be doing anything. Any ideas?
Hello KrisVice,
Thank you for your post!
I have been looking into the code snippet, that you have provided.
In the code snippet you are assigning the value to the cell - " if(some logic){ e.Cell.Value = false }". This way the editor would not be changed.
If you would like to change the value of the editor, I would suggest setting the value as follows: e.Editor.Value = false.
Please do not hesitate to let me know if you have any further questions on this matter.
Thanks for the reply. I knew it was something simple. Another question. When I do e.Editor.Value= false the OnCellChanged method executes twice. This makes sense I guess since you are changing the cell value again. Is there a way to stop that? The reason I'm asking is because I have a condition for when createEvent is false so I don't want it to enter into that condition unless it's the user that triggered the OnCellChanged event.