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

Confirmation Message before delete or save an Item from DataGrid.

1 Answer 475 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Rahul
Top achievements
Rank 1
Rahul asked on 15 Apr 2011, 07:59 AM
Hi,

Confirmation Message before delete or save an Item from DataGrid.
I used a telerik command for deletion of row from datagrid, but user should get a confirmation message before delete of row.
I tried attached code...
<telerik:RadGridView Grid.Row="2" x:Name="orderView" ItemsSource="{Binding Order}" 
                    AutoGenerateColumns="False"  CanUserDeleteRows="{Binding IsChecked, Mode=TwoWay, ElementName=CanUserDeleteRowsCheckBox}"
                             IsReadOnly="{Binding IsChecked, Mode=TwoWay, ElementName=IsReadOnlyCheckBox}" SelectionMode="Extended">
                <telerik:RadGridView.Columns>
                    <telerik:GridViewToggleRowDetailsColumn />
                    <telerik:GridViewSelectColumn Header="Select" x:Name="chkbox" />
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding CustomerName}" Header="Name" />
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding Age}" Header="Age" />
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding Path=COActivity.ActivityDescription}" Header="Age" />
                </telerik:RadGridView.Columns>
</telerik:RadGridView>
  
  
<Button Content=" Delete" Style="{StaticResource GreyButtonStyle}" Command="telerik:RadGridViewCommands.Delete" CommandTarget="{Binding ElementName=gvCustomerOrder}">
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="Click">
                        <cmd:EventToCommand Command="{Binding Path=DeleteCustomerOrderCommand}" PassEventArgsToCommand="True" />
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </Button>
  
private RelayCommand<RoutedEventArgs> _deleteCustomerOrderCommand;
        public RelayCommand<RoutedEventArgs> DeleteCustomerOrderCommand
        {
            get
            {
                if (_deleteCustomerOrderCommand == null)
                {
                    _deleteCustomerOrderCommand = new RelayCommand<RoutedEventArgs>(param => this.DeleteCustomerOrder(param), param => this.CanDeleteCustomerOrder());
                }
                return _deleteCustomerOrderCommand;
            }
        }
        private void DeleteCustomerOrder(RoutedEventArgs e)
        {
             
        }
        private bool CanDeleteCustomerOrder()
        {
            string messageBoxText = "Are you sure you want to delete the selected Orders?";
            string caption = "Confirm";
            MessageBoxButton button = MessageBoxButton.YesNo;
            MessageBoxImage icon = MessageBoxImage.Question;
            MessageBoxResult result = MessageBox.Show(messageBoxText, caption, button, icon);
  
            if (result == MessageBoxResult.Yes)
            {
                return true;
            }
            else
            return false;
        }

1 Answer, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 20 Apr 2011, 12:48 PM
Hi Rahul,

If you want to delete in the grid only after the user confirm it, you will have to make the command for removing the item dependent on the result of the MessageBox. You may implement this only in the command defined in your ViewModel without using the built-in Delete command:
private RelayCommand<object> _deleteCustomerOrderCommand;
        public RelayCommand<object> DeleteCustomerOrderCommand
        {
            get
            {
                if (_deleteCustomerOrderCommand == null)
                {
                    _deleteCustomerOrderCommand = new RelayCommand<object>(param => this.DeleteCustomerOrder(param), param => this.CanDeleteCustomerOrder());
                }
                return _deleteCustomerOrderCommand;
            }
        }
        private void DeleteCustomerOrder(object obj)
        {
            this.Clubs.Remove(obj as Club);
        }
        private bool CanDeleteCustomerOrder()
        {
            string messageBoxText = "Are you sure you want to delete the selected Orders?";
            string caption = "Confirm";
            MessageBoxButton button = MessageBoxButton.YesNo;
            MessageBoxImage icon = MessageBoxImage.Question;
            MessageBoxResult result = MessageBox.Show(messageBoxText, caption, button, icon);
 
            if (result == MessageBoxResult.Yes)
            {
                return true;
            }
            else
            {
                return false;
            }              
        }

In the case above Clubs is the ItemsSource of the grid.

The definition of the button in xaml should be:
<telerik:RadButton Content=" Delete" Width="150">
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="Click">
                        <cmd:EventToCommand Command="{Binding Path=DeleteCustomerOrderCommand}"                                            
                                            CommandParameter="{Binding SelectedItem, ElementName=clubsGrid}"/>
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </telerik:RadButton>

Still, I am sending you a sample project illustrating the solution suggested above.
Let me know in case you need any further assistance.

All the best,
Maya
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
Rahul
Top achievements
Rank 1
Answers by
Maya
Telerik team
Share this question
or