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

BeginInsert() not working in Q3.2009?

9 Answers 151 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Björn Metzinger
Top achievements
Rank 1
Björn Metzinger asked on 02 Dec 2009, 01:46 PM
Hello

Might it happen that the functionality of the BeginInsert() and BeginEdit() methods has been changed in the Q3 (or even Q2) release? It seems that entering insert / edit mode does not work anymore the way it did in the Q1 release.

When I faced problems to get the latest version working, I downloaded and testet this sample project which is working as desired and uses the Q1 binaries. But as soon as I replace the Q1 DLLs with the Q3 ones (plus minor other changes for migration), the insert and edit functionality gets lost.

In particular, in the previous version I could enter the insert mode (adding a new row at the bottom of the grid) by focussing the grid and clicking the insert key, or I could do it programmatically by calling the BeginInsert() method on the grid.

When doing the same with the Q1 gridView, both ways fail!

Am I missing something?

9 Answers, 1 is accepted

Sort by
0
brandon
Top achievements
Rank 1
answered on 03 Dec 2009, 11:52 PM
I have a similar problem with BeginInsert() in Q3.2009.  I have not tried Q1.2009 yet.  I can get it to create a new row once.  But subsequent clicks of my add row button (or pressing the insert key) will not create a new row. 

Edit: nevermind - I see this was fixed in 2009.3.1109
Fixed BeginInsert() will insert new item only once
0
Terry
Top achievements
Rank 1
answered on 25 Mar 2010, 10:39 PM
I am also having this problem in the Silverlight 4 beta with dlls up to 3/16/2010.

Is there a workaround or a planned fix?
0
Nedyalko Nikolov
Telerik team
answered on 31 Mar 2010, 11:57 AM
Hi Terry,

Can you provide with some more details about your scenario?
Generally RadGridView.BeginInsert() method works automatically if your business object has a default (parameter less) constructor.

Greetings,
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.
0
Terry
Top achievements
Rank 1
answered on 31 Mar 2010, 04:47 PM
Hi Nedyalko:

I'm binding the grid ItemsSource property to an RIA entity, System.ServiceModel.DomainServices.Client.EntitySet<WTAB.Web.Models.Charge>.  This works fine, but EntitySet evidently does not support the AddNew method, so I don't get a new row when I type Insert or execute BeginInsert().  I've gotten around this by the following event handler:

        private void gvTimeSheet_AddingNewDataItem(object sender, Telerik.Windows.Controls.GridView.GridViewAddingNewEventArgs e)  
        {  
            WTAB.Web.Models.Charge chg = new WTAB.Web.Models.Charge();  
 
            if (wdc.Charges.Count > 0)  
            {  
                WTAB.Web.Models.Charge prior = wdc.Charges.Last();  
                chg.StartDate = prior.StartDate;  
            }  
            wdc.Charges.Add(chg);  
            gvTimeSheet.SelectedItem = wdc.Charges.Last();  
            gvTimeSheet.BeginEdit();  
        }  
 

This works OK for the most part.  I need the new row to appear at the bottom because the rows are sorted by Date & Time, and the user will be typing in items from a timesheet in this order.

The one problem I am having now is that I want the added row to be in edit mode so the user can enter the data.  What happens with the above code is that, even though the selected row is the last one, the current cell is still in the first row and that's the row that goes into edit mode.  It looks like CurrentCell is read-only, so how can I have the BeginEdit() act on the newly added row at the bottom?

Thanks,

Terry
0
Nedyalko Nikolov
Telerik team
answered on 01 Apr 2010, 10:49 PM
Hi Terry,

You can use RadGridView.ScrollIntoViewAsync() method in order to meet your goals. I'm attaching a sample project that demonstrates this approach.

Sincerely yours,
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.
0
Terry
Top achievements
Rank 1
answered on 04 Apr 2010, 06:17 PM
Thanks, Nedyalko.  That works great!

One funny thing that happens, though is that a blank line is now appearing after the inserted row.  See attached screenshot jpg.

my code:
        private void gvTimeSheet_AddingNewDataItem(object sender, Telerik.Windows.Controls.GridView.GridViewAddingNewEventArgs e)  
        {  
            WTAB.Web.Models.viewDetailCharge chg = new WTAB.Web.Models.viewDetailCharge();  
 
            if (wdc.viewDetailCharges.Count > 0)  
            {  
                WTAB.Web.Models.viewDetailCharge prior = wdc.viewDetailCharges.Last();  
                chg.StartDate = prior.StartDate;  
            }  
            charges.Add(chg);  
 
            gvTimeSheet.ScrollIntoViewAsync(chg  
                , (f) =>  
                {  
                    GridViewRow row = f as GridViewRow;  
                    if (row != null)  
                    {  
                        ((GridViewCell)row.Cells[0]).BeginEdit();  
                    }  
                });  
 
        }  
 
 

I'm using SL4 beta.  The vewDetailCharge object is an entity created from the entity datamodel based on a view in the database.

Here's the xaml:
<navigation:Page x:Class="WTAB.Views.TimeCharges" 
           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
           xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
           xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
           xmlns:radInput="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Input" 
           xmlns:radControl="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls" 
           mc:Ignorable="d" 
           xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation" 
           xmlns:radGridView="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView"   
           xmlns:converters="clr-namespace:WTAB.Views" 
          Title="TimeCharge Page">  
    <navigation:Page.Resources> 
        <!--<converters:TimeSpanConverter x:Name="TimeSpanConverter"/>--> 
        <converters:TimeSpanToStringConverter x:Name="TimeSpanToStringConverter"/>  
    </navigation:Page.Resources> 
  <Grid x:Name="LayoutRoot" > 
        <StackPanel Orientation="Vertical">  
            <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Height="20" VerticalAlignment="Top">  
                <TextBlock Text="Time Charges for: " VerticalAlignment="Center"/>  
                <radInput:RadComboBox x:Name="cboEmployees" VerticalAlignment="Center" Margin="10,0,10,0" DisplayMemberPath="EmpName" 
                     ItemsSource="{Binding}" SelectionChanged="cboEmployees_SelectionChanged">  
                    <!--<radInput:RadComboBoxItem Content="Test Employee" IsSelected="True"/>--> 
                </radInput:RadComboBox> 
                <CheckBox x:Name="chkInactive" Content="Show inactive employees" VerticalAlignment="Center"/>  
            </StackPanel> 
            <radGridView:RadGridView x:Name="gvTimeSheet" AutoGenerateColumns="False" AddingNewDataItem="gvTimeSheet_AddingNewDataItem" RowLoaded="gvTimeSheet_RowLoaded" 
                                     IsReadOnly="False" CanUserInsertRows="True"  ShowColumnFooters="False" ShowGroupFooters="False">  
                <radGridView:RadGridView.Columns> 
                      
                    <!-- Start Date --> 
                    <radGridView:GridViewDataColumn Header="Date" 
                        DataMemberBinding="{Binding StartDate, Mode=TwoWay}" DataFormatString="{}{0:d}">  
                        <radGridView:GridViewDataColumn.CellTemplate> 
                            <DataTemplate> 
                                <TextBlock Text="{Binding StartDate, StringFormat='{}{0:d}'}" /> 
                            </DataTemplate> 
                        </radGridView:GridViewDataColumn.CellTemplate> 
                        <radGridView:GridViewDataColumn.CellEditTemplate> 
                            <DataTemplate> 
                                <radInput:RadDatePicker Loaded="Editor_Loaded" 
                                        SelectedDate="{Binding StartDate, Mode=TwoWay}" /> 
                            </DataTemplate> 
                        </radGridView:GridViewDataColumn.CellEditTemplate> 
                    </radGridView:GridViewDataColumn> 
 
                    <!-- Start Time --> 
                    <radGridView:GridViewDataColumn Header="Start Time" 
                        DataMemberBinding="{Binding StartTimeSpan, Mode=TwoWay}">  
                        <radGridView:GridViewDataColumn.CellTemplate> 
                            <DataTemplate> 
                                <TextBlock Text="{Binding StartTimeSpan, Converter={StaticResource TimeSpanToStringConverter}}" /> 
                            </DataTemplate> 
                        </radGridView:GridViewDataColumn.CellTemplate> 
                        <radGridView:GridViewDataColumn.CellEditTemplate> 
                            <DataTemplate> 
                                <!--<radInput:RadTimePicker TimeInterval="0:15:0"    
                                     SelectedTime="{Binding StartTimeSpan, Mode=TwoWay, StringFormat='{}{0:hh:mm tt}'}" />--> 
                                <radInput:RadTimePicker TimeInterval="0:15:0"     
                                     SelectedTime="{Binding StartTimeSpan, Mode=TwoWay}" /> 
                            </DataTemplate> 
                        </radGridView:GridViewDataColumn.CellEditTemplate> 
                    </radGridView:GridViewDataColumn> 
                      
                    <!-- End Time --> 
                    <radGridView:GridViewDataColumn Header="End Time" 
                        DataMemberBinding="{Binding EndTimeSpan, Mode=TwoWay}">  
                        <radGridView:GridViewDataColumn.CellTemplate> 
                            <DataTemplate> 
                                <TextBlock Text="{Binding EndTimeSpan, Converter={StaticResource TimeSpanToStringConverter}}" /> 
                            </DataTemplate> 
                        </radGridView:GridViewDataColumn.CellTemplate> 
                        <radGridView:GridViewDataColumn.CellEditTemplate> 
                            <DataTemplate> 
                                <!--<radInput:RadTimePicker TimeInterval="0:15:0"    
                                     SelectedTime="{Binding EndTimeSpan, Mode=TwoWay, StringFormat='{}{0:hh:mm tt}'}" />--> 
                                <radInput:RadTimePicker TimeInterval="0:15:0"     
                                     SelectedTime="{Binding EndTimeSpan, Mode=TwoWay}" /> 
                            </DataTemplate> 
                        </radGridView:GridViewDataColumn.CellEditTemplate> 
                    </radGridView:GridViewDataColumn> 
                     
                    <!-- Customer --> 
                    <radGridView:GridViewComboBoxColumn DataMemberBinding="{Binding CustomerID, Mode=TwoWay}" Header="Customer" DisplayMemberPath="CustName" SelectedValueMemberPath="CustomerID" /> 
                      
                    <!--<radGridView:GridViewDataColumn Header="Customer" DataMemberBinding="{Binding CustomerID, Mode=TwoWay}" 
                                                    DataFormatString="{}{0:#0}">  
                        <radGridView:GridViewDataColumn.CellTemplate> 
                            <DataTemplate> 
                                <radInput:RadComboBox x:Name="cboCustomers" DisplayMemberPath="CustName" DataContext="{Binding}" /> 
                            </DataTemplate> 
                        </radGridView:GridViewDataColumn.CellTemplate> 
                        <radGridView:GridViewDataColumn.CellEditTemplate> 
                            <DataTemplate> 
                                <TextBox Text="{Binding CustomerID, Mode=TwoWay, StringFormat='{}{0:#0}'}"/>  
                            </DataTemplate> 
                        </radGridView:GridViewDataColumn.CellEditTemplate> 
                    </radGridView:GridViewDataColumn>--> 
                      
                    <!-- Project --> 
                    <radGridView:GridViewDataColumn Header="Project" DataMemberBinding="{Binding ProjectID, Mode=TwoWay}">  
                        <radGridView:GridViewDataColumn.CellTemplate> 
                            <DataTemplate> 
                                <TextBlock Text="{Binding ProjectID}" /> 
                            </DataTemplate> 
                        </radGridView:GridViewDataColumn.CellTemplate> 
                        <radGridView:GridViewDataColumn.CellEditTemplate> 
                            <DataTemplate> 
                                <TextBox Text="{Binding ProjectID, Mode=TwoWay}"/>  
                            </DataTemplate> 
                        </radGridView:GridViewDataColumn.CellEditTemplate> 
                    </radGridView:GridViewDataColumn> 
                      
                    <!-- Description --> 
                    <radGridView:GridViewDataColumn Header="Description" DataMemberBinding="{Binding Description, Mode=TwoWay}">  
                        <radGridView:GridViewDataColumn.CellTemplate> 
                            <DataTemplate> 
                                <TextBlock Text="{Binding Description}" /> 
                            </DataTemplate> 
                        </radGridView:GridViewDataColumn.CellTemplate> 
                        <radGridView:GridViewDataColumn.CellEditTemplate> 
                            <DataTemplate> 
                                <TextBox Text="{Binding Description, Mode=TwoWay}"/>  
                            </DataTemplate> 
                        </radGridView:GridViewDataColumn.CellEditTemplate> 
                    </radGridView:GridViewDataColumn> 
                </radGridView:RadGridView.Columns> 
            </radGridView:RadGridView> 
            <radControl:RadButton x:Name="btnAdd" Content="Add Time Charge" Click="btnAdd_Click" />     <!-- does BeginInsert(), which returns false --> 
        </StackPanel> 
    </Grid> 
</navigation:Page> 
 







0
Nedyalko Nikolov
Telerik team
answered on 07 Apr 2010, 10:29 PM
Hello Terry,

Indeed this is very weird. Unfortunately I cannot simulate this issue, but I spot a possible problem in your code behind. Could you please add e.Cancel = true in your AddingNewDataItem event hander, and let me know about the result.

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.
0
Terry
Top achievements
Rank 1
answered on 07 Apr 2010, 10:44 PM
Hi Nedyalko:

Setting e.Cancel = true results in no action occuring at all.  That is, the grid does not show an extra item and none of the existing rows goes into edit mode.

Terry
0
Nedyalko Nikolov
Telerik team
answered on 13 Apr 2010, 11:25 AM
Hi Terry,

Then you do not need this AddingNewDataItem event handler. If this is your case that means that you've bound RadGridView to an IList<T> collection and T has a default constructor so this event handler is not necessary. You have to bind RadGridView to an ObservableCollection<T> in order to make this code working (with e.Cancel = true, otherwise 2 items will be added). Please remove this event from the picture and let me know about the result, or bind grid to an ObservableCollection<T>, or send me a sample project which I can debug on my side.

Greetings,
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
Björn Metzinger
Top achievements
Rank 1
Answers by
brandon
Top achievements
Rank 1
Terry
Top achievements
Rank 1
Nedyalko Nikolov
Telerik team
Share this question
or