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

Cannot Insert/Delete after Inserting once

1 Answer 101 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Joachim Karlsson
Top achievements
Rank 1
Joachim Karlsson asked on 24 Aug 2010, 02:11 PM

Hey there!

I get insert, delete and Edit to work

But when i insert one row, delete gets disabled and insert row aswell.

<Window x:Class="Administration.Window1"
    xmlns:telerikGrid="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView"
    xmlns:telerikQuickStart="clr-namespace:Telerik.Windows.Controls.QuickStart;assembly=Telerik.Windows.Controls" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" d:DesignWidth="833" SizeToContent="WidthAndHeight" d:DesignHeight="567">
 
 
    <Grid Height="528" Width="815">
             
        <Border telerikQuickStart:ThemeAwareBackgroundBehavior.IsEnabled="True" Margin="0,81,-2,15" />
 
        <StackPanel Orientation="Horizontal" Margin="102,0,98,456" Height="22.301" VerticalAlignment="Bottom" HorizontalAlignment="Center">
            <telerik:RadButton Width="150" Content="Delete selected rows" Margin="0,0,5,0"
                               Command="telerikGrid:RadGridViewCommands.Delete" CommandTarget="{Binding ElementName=RadGridView1}" VerticalAlignment="Top" />
            <telerik:RadButton Width="150" Content="Add new row" Margin="0,0,5,0"
                               Command="telerikGrid:RadGridViewCommands.BeginInsert" CommandTarget="{Binding ElementName=RadGridView1}" VerticalAlignment="Top" />
            <telerik:RadButton Width="150" Content="Save insert/edit" Margin="0,0,5,0"
                               Command="telerikGrid:RadGridViewCommands.CommitEdit" CommandTarget="{Binding ElementName=RadGridView1}" Height="Auto" VerticalContentAlignment="Center" VerticalAlignment="Top" />
            <telerik:RadButton Width="150" Content="Cancel insert/edit"
                               Command="telerikGrid:RadGridViewCommands.CancelRowEdit" CommandTarget="{Binding ElementName=RadGridView1}" VerticalAlignment="Top" />
        </StackPanel>
 
 
        <telerik:RadGridView x:Name="RadGridView1" ItemsSource="{Binding}"
                             CanUserInsertRows="True"
                             CanUserDeleteRows="True"
                             ActionOnLostFocus="CommitEdit"
                             RowEditEnded="PricingGrid_RowEditEnded" Margin="0,81,0,0"  >
            <telerik:RadGridView.RowStyle>
                    <Style TargetType="telerik:GridViewRow">
                        <Setter Property="MinHeight" Value="40" />
                    </Style>
                </telerik:RadGridView.RowStyle>
                <telerik:RadGridView.Columns>
 
                <telerik:GridViewColumn>
                        <telerik:GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <telerik:RadButton Content="Delete" Command="telerikGrid:RadGridViewCommands.Delete" CommandParameter="{Binding}" />
                            </DataTemplate>
                        </telerik:GridViewColumn.CellTemplate>
                    </telerik:GridViewColumn>
                     
                     
                     
                    <telerik:GridViewToggleRowDetailsColumn />
                     
              </telerik:RadGridView.Columns>
                <telerik:RadGridView.RowDetailsTemplate>
                    <DataTemplate>
                        <telerik:RadTabControl BackgroundVisibility="Collapsed" x:Name="RadTabControl1" Margin="10" VerticalAlignment="Center" Background="Transparent">
                            <telerik:RadTabItem Header="Description" DataContext="{Binding}" Margin="10,0,0,0" Height="24" Foreground="Black">
                                <Grid Width="Auto" HorizontalAlignment="Stretch">
                                    <Grid.RowDefinitions>
                                        <RowDefinition />
                                        <RowDefinition />
                                        <RowDefinition />
                                        <RowDefinition />
                                        <RowDefinition />
                                        <RowDefinition />
                                        <RowDefinition />
                                        <RowDefinition Height="15" />
                                    </Grid.RowDefinitions>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="Auto" />
                                        <ColumnDefinition Width="Auto" />
                                        <ColumnDefinition Width="Auto" />
                                    </Grid.ColumnDefinitions>
                                    
                                    <TextBlock Text="Description: " Margin="5,10,0,0" FontWeight="Bold" Grid.Row="0" Grid.Column="1" />
                                    <TextBlock Text="{Binding strDescription}" Margin="5,10,0,0" Grid.Row="0" Grid.Column="2" />
                                    <!--<TextBlock Text="Country: " Margin="5,0,0,0" FontWeight="Bold" Grid.Row="1" Grid.Column="1" />
                                    <TextBlock Text="{Binding nCountry}" Margin="5,0,0,0" Grid.Row="1" Grid.Column="2" />-->
                                    
                                     
                                </Grid>
                            </telerik:RadTabItem>
                        </telerik:RadTabControl>
                    </DataTemplate>
                </telerik:RadGridView.RowDetailsTemplate>
            </telerik:RadGridView>
        
        <StackPanel Height="46.14" Margin="0" Name="stackPanel1" VerticalAlignment="Top" Orientation="Horizontal" HorizontalAlignment="Center">
            <telerik:RadButton  Height="45.371" Width="61.52" ClickMode="Release" HorizontalAlignment="Center">
                 Artiklar
            </telerik:RadButton>
            <telerik:RadButton Height="45.371" Width="61.52" ClickMode="Release" HorizontalAlignment="Center">
                 
                Priser
            </telerik:RadButton>
            <telerik:RadButton Height="45.371" Width="61.52" ClickMode="Release" HorizontalAlignment="Center">
                 ETC
            </telerik:RadButton>
            <telerik:RadButton Height="45.371" Width="61.52" ClickMode="Release" HorizontalAlignment="Center">
                 ETC
            </telerik:RadButton>
            <telerik:RadButton Height="45.371" Width="61.52" ClickMode="Release" HorizontalAlignment="Center">
                 OSV
            </telerik:RadButton>
            <telerik:RadButton Height="45.371" Width="61.52" ClickMode="Release" HorizontalAlignment="Center">
                OSV
            </telerik:RadButton>
            <telerik:RadButton Height="45.371" Width="61.52" ClickMode="Release" HorizontalAlignment="Center">
                 Artiklar
            </telerik:RadButton>
            <telerik:RadButton Height="45.371" Width="61.52" ClickMode="Release" HorizontalAlignment="Center">
               Priser
            </telerik:RadButton>
            <telerik:RadButton Height="45.371" Width="61.52" ClickMode="Release" HorizontalAlignment="Center">
                OSV
            </telerik:RadButton>
            <telerik:RadButton Height="45.371" Width="61.52" ClickMode="Release" ClipToBounds="False" HorizontalAlignment="Center">
                 ETC
            </telerik:RadButton>
        </StackPanel>
    </Grid>
</Window>
 
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Telerik.Windows.Data;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Collections;
using Telerik.Windows.Controls;
using Telerik.Windows.Controls.GridView;
using System.Linq;
using System.Globalization;
using Telerik.Windows.Controls.Charting;
 
namespace Administration
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        public CollectionViewSource Source { get; set; }
 
        public List<Categories> _EditedCategories;
 
        public Window1()
        {
            InitializeComponent();
            this.Source = new CollectionViewSource();
            _EditedCategories = new List<Categories>();
 
            BindData();
        }
 
        private void BindData()
        {
            var wcomPosDB = new WcomPosProductDataContext();
 
            //var getCats = (from u in wcomPosDB.tblCategories
            //               join c in wcomPosDB.tblCategoryDescriptions on u.nID equals c.nCategoryID
            //               select new { ID = u.nID, Description = u.strDescription, Country = c.nCountry }).ToList();
 
            var testCats = from u in wcomPosDB.tblCategories
                           select u;
 
            //select new { ID = u.nID, Description = u.strDescription }).ToList();
 
 
            var list = new ObservableCollection<Categories>();
 
            foreach (var cat in testCats)
            {
                list.Add(new Categories { nID = cat.nID, strDescription = cat.strDescription });
            }
 
            Source.Source = list;
 
            this.DataContext = Source.View;
 
        }
 
 
 
        private void PricingGrid_RowEditEnded(object sender, Telerik.Windows.Controls.GridViewRowEditEndedEventArgs e)
        {
            if (e.EditOperationType == Telerik.Windows.Controls.GridView.GridViewEditOperationType.Insert)
            {
                this.DataContext = Source.View.OfType<Categories>().OrderBy(c => c.nID);
 
                Source.Source = this.DataContext;
 
                RadGridView1.SelectedItem = e.NewData;
                RadGridView1.ScrollIntoView(e.NewData);
 
            }
 
 
            //add edited item to new list, then use this list to update the database..
            if (e.NewData != null)
            {
                _EditedCategories.Add((Categories)e.NewData);
            }
 
             
        }
 
        public class FuncValueConverter : IValueConverter
        {
            private readonly Func<object, object, object> convertFunc;
 
            public FuncValueConverter(Func<object, object, object> convertFunc)
            {
                this.convertFunc = convertFunc;
            }
 
            public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
            {
                return this.convertFunc(value, parameter);
            }
 
            public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
            {
                throw new NotImplementedException();
            }
        }
 
 
 
        public class Categories
        {
            public long nID { get; set; }
            public string strDescription { get; set; }
        }
       
    }
}
 
 
Im new to Telerik, and this been bugging me for a while now.
 
Hope someone out there can help me.
 
Regards Joachim.

1 Answer, 1 is accepted

Sort by
0
Nedyalko Nikolov
Telerik team
answered on 27 Aug 2010, 08:49 AM
Hi Joachim Karlsson,

I guess that RadGridView remains in edit mode. Could you please try to add additional "Save" column?

<telerik:GridViewColumn>
                        <telerik:GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <telerik:RadButton Content="Save" Command="telerikGrid:RadGridViewCommands.CommitEdit" />
                            </DataTemplate>
                        </telerik:GridViewColumn.CellTemplate>
                    </telerik:GridViewColumn>

After edit is complete click on a Save button, and let me know how it works.

All the best,
Nedyalko Nikolov
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
Joachim Karlsson
Top achievements
Rank 1
Answers by
Nedyalko Nikolov
Telerik team
Share this question
or