This question is locked. New answers and comments are not allowed.
Mahendiran
Top achievements
Rank 1
Mahendiran
asked on 20 Jul 2010, 02:00 PM
Hello,
I am using the latest version of RadGridView and am facing an annoying problem. My scenario is as follows.
I have enabled ShowInsertRow and after the user enters insert mode, i want them to be able to cancel the insert without pressing Esc key. I have a button which when clicked calls CancelEdit() but the problem is that the user is inside of a cell which is a required field and validation event is fired and is not allowing the user to come out of the insert mode.
Thanks in advance
I am using the latest version of RadGridView and am facing an annoying problem. My scenario is as follows.
I have enabled ShowInsertRow and after the user enters insert mode, i want them to be able to cancel the insert without pressing Esc key. I have a button which when clicked calls CancelEdit() but the problem is that the user is inside of a cell which is a required field and validation event is fired and is not allowing the user to come out of the insert mode.
Thanks in advance
6 Answers, 1 is accepted
0
Hello Mahendiran,
Can you please try with the CancelRowEdit command as shown in this example:
GridView Commands
Best wishes,
Veskoni
the Telerik team
Can you please try with the CancelRowEdit command as shown in this example:
GridView Commands
Best wishes,
Veskoni
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
0
Mahendiran
Top achievements
Rank 1
answered on 20 Jul 2010, 03:02 PM
Thanks,
but is there a way to do it from code behind. I have a button which does discard changes. I want the user to be able to click it and cancel the Row edit
but is there a way to do it from code behind. I have a button which does discard changes. I want the user to be able to click it and cancel the Row edit
0
Mahendiran
Top achievements
Rank 1
answered on 20 Jul 2010, 05:44 PM
Hey..
i tried with the RadGridViewCommand.. still the validation occurs and it prevents me from Cancelling the Insert/Edit. Please help... It is urgent
i tried with the RadGridViewCommand.. still the validation occurs and it prevents me from Cancelling the Insert/Edit. Please help... It is urgent
0
Hello Mahendiran,
Please find attached a sample project. I have marked the Name property as Required. Now, when you try to insert a new row and click on the Cancel button - the validation is not fired and the row is not created.
Hope this helps.
All the best,
Veskoni
the Telerik team
Please find attached a sample project. I have marked the Name property as Required. Now, when you try to insert a new row and click on the Cancel button - the validation is not fired and the row is not created.
Hope this helps.
All the best,
Veskoni
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
0
Lester
Top achievements
Rank 1
answered on 19 Aug 2010, 07:53 PM
Hello Veskoni,
Thanks a lot for the help, I'm trying to use that functionality but using usercontrols and RowDetailsTemplate.
I modify your code and added a user control with the buttons, can you please see what I'm missing in order to make this work?
We are almost there!
Thanks !!!!!
Lester
.
Thanks a lot for the help, I'm trying to use that functionality but using usercontrols and RowDetailsTemplate.
I modify your code and added a user control with the buttons, can you please see what I'm missing in order to make this work?
We are almost there!
Thanks !!!!!
Lester
.
<UserControl x:Class="Commands.MainPage" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" xmlns:telerikGrid="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView" xmlns:my="clr-namespace:Commands" mc:Ignorable="d" d:DesignHeight="700" d:DesignWidth="700"> <UserControl.Resources> <my:MyViewModel x:Key="MyViewModel"/> <DataTemplate x:Key="SilverlightControl"> <my:SilverlightControl /> </DataTemplate> </UserControl.Resources> <Grid x:Name="LayoutRoot" Background="White" DataContext="{StaticResource MyViewModel}"> <Grid.RowDefinitions> <RowDefinition Height="*"/> <RowDefinition Height="Auto" /> </Grid.RowDefinitions> <telerik:RadGridView Grid.Row="0" Name="clubsGrid" ShowInsertRow="True" ItemsSource="{Binding Clubs}" AutoGenerateColumns="False" ActionOnLostFocus="None" RowDetailsTemplate="{StaticResource SilverlightControl}" RowDetailsVisibilityMode="VisibleWhenSelected" AddingNewDataItem="clubsGrid_AddingNewDataItem" Margin="5"> <telerik:RadGridView.Columns> <telerik:GridViewDataColumn DataMemberBinding="{Binding Name}"/> <telerik:GridViewDataColumn DataMemberBinding="{Binding Established}" Header="Est." DataFormatString="{}{0:yyyy}"/> <telerik:GridViewDataColumn DataMemberBinding="{Binding StadiumCapacity}" Header="Stadium" DataFormatString="{}{0:N0}"/> </telerik:RadGridView.Columns> </telerik:RadGridView> <StackPanel Grid.Row="1" Orientation="Horizontal"> <telerik:RadButton Width="150" Content="Add new row" Margin="0,0,5,0" Command="telerikGrid:RadGridViewCommands.BeginInsert" CommandTarget="{Binding ElementName=clubsGrid}" /> <telerik:RadButton Width="150" Content="Cancel insert/edit" Command="telerikGrid:RadGridViewCommands.CancelRowEdit" CommandTarget="{Binding ElementName=clubsGrid}" /> </StackPanel> </Grid> </UserControl> using System.Windows; using System.Windows.Controls; using System.Collections.ObjectModel; using System.Windows.Input; using Telerik.Windows.Controls; using Telerik.Windows.Controls.GridView; namespace Commands { public partial class MainPage : UserControl { public MainPage() { ICommand insertRowCommand = RadGridViewCommands.BeginInsert; ICommand cancelRowEditCommand = RadGridViewCommands.CancelRowEdit; InitializeComponent(); } private void clubsGrid_AddingNewDataItem(object sender, GridViewAddingNewEventArgs e) { e.Cancel = true; Club club = new Club(); ObservableCollection<Club> itemsSource = (ObservableCollection<Club>)this.clubsGrid.ItemsSource; itemsSource.Add(club); this.clubsGrid.CurrentItem = club; this.clubsGrid.ScrollIntoViewAsync(club, this.OnNewClubAdded); //this.clubsGrid.BeginEdit(); } private void OnNewClubAdded(FrameworkElement row) { ((GridViewRow)row).DetailsVisibility = Visibility.Visible; this.clubsGrid.ShowInsertRow = false; } } } <UserControl x:Class="Commands.SilverlightControl" mc:Ignorable="d" d:DesignHeight="173" d:DesignWidth="474" xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"> <Grid x:Name="LayoutRoot" Background="White" DataContext="{Binding}"> <sdk:Label Height="28" HorizontalAlignment="Left" Margin="68,46,0,0" Name="label1" VerticalAlignment="Top" Width="120" Content="Name" /> <TextBox Height="23" HorizontalAlignment="Left" Margin="204,42,0,0" Name="textBoxName" VerticalAlignment="Top" Width="204" Text="{Binding Name,Mode=TwoWay}" /> <Button Content="Save" Height="23" HorizontalAlignment="Left" Margin="235,80,0,0" Name="buttonSave" VerticalAlignment="Top" Width="92" Click="buttonSave_Click" /> <Button Content="Cancel" Height="23" HorizontalAlignment="Left" Margin="333,80,0,0" Name="buttonCancel" VerticalAlignment="Top" Width="75" Click="buttonCancel_Click" /> </Grid> </UserControl> using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; namespace Commands { public partial class SilverlightControl : UserControl { public SilverlightControl() { InitializeComponent(); } private void buttonSave_Click(object sender, RoutedEventArgs e) { MessageBox.Show("Save to DB"); } private void buttonCancel_Click(object sender, RoutedEventArgs e) { MessageBox.Show("I need to remove that temp record I created, close the RowDetailsTemplate and reactivate the Add new record bar. The same if I click on another record and enter into edit mode, I need to cancel the add new event "); } } } 0
Hi Lester,
You can define the CancelEdit event handler as follows:
Regards,
You can define the CancelEdit event handler as follows:
private void buttonCancel_Click(object sender, RoutedEventArgs e){ var grid = buttonCancel.ParentOfType<RadGridView>(); grid.Items.Remove(buttonCancel.DataContext); grid.ShowInsertRow = true;}Regards,
Veskoni
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