This is a migrated thread and some comments may be shown as answers.

Confirmation dialog on bool Cell Edit (MVVM)

4 Answers 91 Views
GridView
This is a migrated thread and some comments may be shown as answers.
iahulg
Top achievements
Rank 1
iahulg asked on 18 Apr 2016, 03:25 PM

Hello. 
I have boolean column in my grid with custom checkbox template:

<telerik:GridViewDataColumn Header="Custom Bool Column"
                   EditTriggers="CellClick"
                   DataMemberBinding="{Binding LabelReady, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                   HeaderTextAlignment="Center">
   <telerik:GridViewColumn.CellTemplate>
      <DataTemplate>
         <Image Height="20" Margin="2"  Stretch="Uniform">
            <Image.Style>
               <Style TargetType="{x:Type Image}">
                  <Setter Property="Source" Value="/red-cross.png"/>
                     <Style.Triggers>
                        <DataTrigger Binding="{Binding LabelReady}" Value="True">
                           <Setter Property="Source" Value="/green-tick.png"/>
                        </DataTrigger>
                     </Style.Triggers>
                  </Style>
               </Image.Style>
            </Image>
         </DataTemplate>
      </telerik:GridViewColumn.CellTemplate>
   </telerik:GridViewDataColumn>

And I need to add a confirmation dialog on cell edit using MVVM approach, i.e. now when user double clicks on the image, the value is changed to opposite, how can I add a dialog, which will ask user if he really wants to change the value, and change the value in cell only if he press "Yes" ? 

 

4 Answers, 1 is accepted

Sort by
0
Stefan Nenchev
Telerik team
answered on 21 Apr 2016, 07:39 AM
Hello Vitali,

You can use the Telerik EventToCommandBehavior in order to keep the MVVM pattern for your application. Eventually, you can use it to bind the "Click"(or any other) event of the CheckBox in the CellEditTemplate of your column to a custom command in your ViewModel. 

I have added a sample project that suggests a possible scenario. Please review it and consider taking a similar approach at your end. 

Regards,
Stefan Nenchev
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
iahulg
Top achievements
Rank 1
answered on 21 Apr 2016, 08:53 AM
Hi, Stefan !
Thanks for your help. The solution looks pretty elegant. 
Can the same be achieved without entering cell edit mode, i.e. just by (double) clicking on readonly cell ? 
0
Accepted
Stefan Nenchev
Telerik team
answered on 22 Apr 2016, 07:49 AM
Hi,

You can use a ToggleButton instead of a CheckBox and predefine its Control Template. Please review the updated sample. You can consider such approach at your end and apply some further customizations.

Regards,
Stefan Nenchev
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
iahulg
Top achievements
Rank 1
answered on 22 Apr 2016, 02:26 PM
Thanks again, Stefan. 
It worked well for me)
Tags
GridView
Asked by
iahulg
Top achievements
Rank 1
Answers by
Stefan Nenchev
Telerik team
iahulg
Top achievements
Rank 1
Share this question
or