I have Xamgrid in when when the user edits value I am show a messagebox
If value >20 then it should show message that is value you entered is > 20 ok/cancel
Ok should restore value and cancel should bring back the whole value
What should be done so that cancel restores the original value?
In cell exited edit mode I have
if (e.Cell.Row.RowType == RowType.DataRow) { if (null != e.Cell.Row.Data) { xxx data = e.Cell.Row.Data as xxx; if(data.field1 > 20) { MessageBoxResult result = MessageBox.Show("adjust value by 20.OK/Cancel?", "xxx", MessageBoxButton.OKCancel);
if (result == MessageBoxResult.Cancel) { } } } }
Hi,
Try this approach:
private void XGridCellExitingEditMode(object sender, ExitEditingCellEventArgs e) { if (e.Cell.Column.Key == "Int") { int resolvedValue = (int)Convert.ChangeType(e.NewValue, typeof(int), CultureInfo.CurrentCulture); if (!(resolvedValue >= 0 && resolvedValue <= 100)) { if (MessageBox.Show("The value is out of the range [0; 100]. Do you want to save it anyway?", "Warning", MessageBoxButton.OKCancel) == MessageBoxResult.Cancel) { this.XGrid.ExitEditMode(true); } } } }
Invoking .ExitEditMode(true) forces the cell to exit edit mode without saving the value.
Hope this helps
I tired this code
It just keeps popping up the message box
Also the e.NewValue is not the new value when its edited for the first time
user still is able to enter 300
Only when he tries to edit the textbox again he gets the message
and the message keeps popping up even if he does cancel
Any ideas why
Also i noticed that if user has originalvalue as 2 and he enters 109 does a cancel, it does not keep the grid with the old value i.e 2
it still shows grid populated with 109
Attached is the sample code
Any help is appreciated
If you change sample with
<ig:TemplateColumn Key="Age" HorizontalContentAlignment="Right" IsHideable="False" IsResizable="False" HeaderText="Age"> <ig:TemplateColumn.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding Age}"></TextBlock> </DataTemplate> </ig:TemplateColumn.ItemTemplate> <ig:TemplateColumn.EditorTemplate> <DataTemplate> <TextBox Text="{Binding Age, Mode=TwoWay}" ></TextBox> </DataTemplate> </ig:TemplateColumn.EditorTemplate> </ig:TemplateColumn>
the e.NewValue will never have new value
And in my code i am using template columns