Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
380
XamCheckEditor with Confirmation
posted

I have a checkbox in the XamDataGrid. I want to show a dialog "Are you sure you want to Remove?" to confirm the user's choice.

The first issue: show the dialog as soon as the user clicks on the checkbox (not when the checkbox loses focus). I solved this issue by calling EndEditMode.

Second issue: I am also able to show a message box, but I am unable to "uncheck" the checkbox. In order to do this, I subscribe to the EditModeEnding event and try to set AcceptChanges. Although the changes don't get propagated, the grid still shows the cell as checked. Not sure if this is the best way to go about doing this.

<ig:Field Name="Remove" Label="Remove" >
    <ig:Field.Settings>
        <ig:FieldSettings>
            <ig:FieldSettings.EditorStyle>
                <Style TargetType="{x:Type igEditors:XamCheckEditor}">
                    <EventSetter Event="ValueChanged" Handler="cValueChanged"/>
                </Style>
            </ig:FieldSettings.EditorStyle>
        </ig:FieldSettings>
    </ig:Field.Settings>
</ig:Field>


void cValueChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
{
    XamCheckEditor editor = sender as XamCheckEditor;
    editor.EndEditMode(true, false);
}

void grid_EditModeEnding(object sender, Infragistics.Windows.DataPresenter.Events.EditModeEndingEventArgs e)
{
    if (e.Cell.Field.Name == "Remove" && (bool)e.Editor.Value)
    {
        ///////////////////////////////////////////////////////////////////////////////////////
        //BUGBUG:: This is not working as expected. Maybe my logic is incorrect. Could you help?
        ///////////////////////////////////////////////////////////////////////////////////////
        if (MessageBoxResult.No == MessageBox.Show("Yes, if sure", "SS", MessageBoxButton.YesNo))
        {
            e.AcceptChanges = false;

            // NOTE: If this is uncommented, the edit mode does not end
            //e.Cancel = !e.AcceptChanges;
        }

        Debug.WriteLine("grid_EditModeEnding");
    }
}

 

I tried to solve this behavior by having a Checkbox as the CellValuePresenter. I can show the dialog when the user clicks on the checkbox. However, if the user decides to "cancel" the check, the user still has to focus away from the checkbox.

I have enclosed the solution as an attachment. Can someone check to see if there is something incorrect in my solution? Or provide an appropriate solution?

 

Thanks in advance.

WpfApplication1.zip
Parents
No Data
Reply
  • 30945
    Verified Answer
    Offline posted

    Hello,

     

    I have modified the sample applicaiotn that you attached in order to implement the functionality that you want. For the “Sure” field where you use a CheckBox as ControlTemplate I handled the Checked event and the event handler shows the dialog. For the “Remove” field I added an EventSetter for the Loaded event in the Style for the XamCheckEditor. In the event handler using the Utilities class I get the ValueEditorCheckBox and hadle its Checked event.

     

    If you have any further questions please do not hesitate to ask.

     

    Sincerely,

    Krasimir

    Developer Support Engineer

    Infragistics

    www.infragistics.com/support

    WpfApplication1.zip
Children
No Data