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 the feedback. I am glad, that you have found a solution to your issue.
Hi. I found a way around the OnCellChanged method being called twice. My original question was answered. Thanks.
I am just checking if you have any further questions on this matter. Please do not hesitate to let me know if you do.
I have been looking into your second question and you are right, since you are manually changing the value of the cell, the event fires second time.
One possible solution if to change the value of the cell in the EditModeEnding or EditModeEnded event. They would fire after the cell if exits or it's about to exit the edit mode.
More about these events you can find on the following link from our documentation: http://help.infragistics.com/Help/Doc/WPF/2015.1/CLR4.0/html/InfragisticsWPF4.DataPresenter.v15.1~Infragistics.Windows.DataPresenter.XamDataGrid_members.html.
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.