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

Add New Row - Dropped

8 Answers 155 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Nick Wood
Top achievements
Rank 1
Nick Wood asked on 11 Jan 2011, 08:08 AM
Hi

I have an issue where I am adding a new row to a data grid, but when I press enter or navigate away then new row is just dropped.There are no errors thown or validation issues. The ItemSource is a ria services collection. What could be causing this?

Below is the xaml for the grid:
<telerikGrid:RadGridView x:Name="RadGridView1" Grid.Column="0" Grid.Row="5" Grid.ColumnSpan="4" CanUserFreezeColumns="true"
                                Margin="0,0,0,1" ShowGroupPanel="False" MaxHeight="280"
                                AutoGenerateColumns="False" CanUserInsertRows="True" ShowInsertRow="True"
                                RowIndicatorVisibility="Collapsed"
                                VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
                                AddingNewDataItem="RadGridView1_AddingNewDataItem" 
                                IsEnabled="{Binding EditSiteProfile.SiteProfileId, Converter={StaticResource GuidIdEmptyToNotEnabledConverter}}"
                                ItemsSource="{Binding SiteProfileDaysList}">
                  
                <telerikGrid:RadGridView.ChildTableDefinitions>
                    <telerikGrid:GridViewTableDefinition />
                </telerikGrid:RadGridView.ChildTableDefinitions>
                <telerikGrid:RadGridView.Columns>
                    <telerikGrid:GridViewComboBoxColumn ItemsSourceBinding="{Binding Data, Source={StaticResource ProfileDaysDC}}" 
                                                         DataMemberBinding="{Binding DayId, Mode=TwoWay}" DisplayMemberPath="DayName" 
                                                         SelectedValueMemberPath="DayId">
                        <telerikGrid:GridViewComboBoxColumn.Header>
                            <TextBlock Text="Day" Foreground="White" />
                        </telerikGrid:GridViewComboBoxColumn.Header>
                    </telerikGrid:GridViewComboBoxColumn>
                    <UIGridColumnExtensions:TimePickerColumn DataMemberBinding="{Binding RestaurantOpenTime}" TimeInterval="0:30:0" DataFormatString="{}{0:h:mm tt}">
                        <UIGridColumnExtensions:TimePickerColumn.Header>
                            <TextBlock Text="Rest Open" Foreground="White" />
                        </UIGridColumnExtensions:TimePickerColumn.Header>
                    </UIGridColumnExtensions:TimePickerColumn>
                    <UIGridColumnExtensions:TimePickerColumn DataMemberBinding="{Binding RestaurantCloseTime}" TimeInterval="0:30:0" DataFormatString="{}{0:h:mm tt}">
                        <UIGridColumnExtensions:TimePickerColumn.Header>
                            <TextBlock Text="Rest Close" Foreground="White" />
                        </UIGridColumnExtensions:TimePickerColumn.Header>
                    </UIGridColumnExtensions:TimePickerColumn>
                    <UIGridColumnExtensions:TimePickerColumn DataMemberBinding="{Binding DriveThruOpenTime}" TimeInterval="0:30:0" DataFormatString="{}{0:h:mm tt}">
                        <UIGridColumnExtensions:TimePickerColumn.Header>
                            <TextBlock Text="Drive Open" Foreground="White" />
                        </UIGridColumnExtensions:TimePickerColumn.Header>
                    </UIGridColumnExtensions:TimePickerColumn>
                    <UIGridColumnExtensions:TimePickerColumn DataMemberBinding="{Binding DriveThruCloseTime}" TimeInterval="0:30:0" DataFormatString="{}{0:h:mm tt}">
                        <UIGridColumnExtensions:TimePickerColumn.Header>
                            <TextBlock Text="Drive Close" Foreground="White" />
                        </UIGridColumnExtensions:TimePickerColumn.Header>
                    </UIGridColumnExtensions:TimePickerColumn>
                </telerikGrid:RadGridView.Columns>
                <telerikGrid:RadGridView.HierarchyChildTemplate>
                    <DataTemplate>
                        <telerikGrid:RadGridView x:Name="RadGridView_SiteProfileDayParts" Grid.Column="0" Grid.Row="5" Grid.ColumnSpan="4" CanUserFreezeColumns="true"
                                Margin="0,0,0,1" ShowGroupPanel="False" MaxHeight="100"
                                DataLoadMode="Asynchronous" ScrollMode="Deferred"
                                AutoGenerateColumns="False" CanUserInsertRows="True" ShowInsertRow="True"
                                RowIndicatorVisibility="Collapsed"
                                VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
                                AddingNewDataItem="RadGridView_SiteProfileDayParts_AddingNewDataItem"
                                ItemsSource="{Binding SiteProfileDayParts}">
  
                            <telerikGrid:RadGridView.Columns>
                                <telerikGrid:GridViewComboBoxColumn ItemsSourceBinding="{Binding Data, Source={StaticResource DayPartsDC}}" 
                                                         DataMemberBinding="{Binding DayPartId, Mode=TwoWay}" DisplayMemberPath="DayPartName" 
                                                         SelectedValueMemberPath="DayPartId">
                                    <telerikGrid:GridViewComboBoxColumn.Header>
                                        <TextBlock Text="Day Part Name" Foreground="White" />
                                    </telerikGrid:GridViewComboBoxColumn.Header>
                                </telerikGrid:GridViewComboBoxColumn>
                                <UIGridColumnExtensions:TimePickerColumn DataMemberBinding="{Binding StartTime}" TimeInterval="0:30:0" DataFormatString="{}{0:h:mm tt}">
                                    <UIGridColumnExtensions:TimePickerColumn.Header>
                                        <TextBlock Text="Start Time" Foreground="White" />
                                    </UIGridColumnExtensions:TimePickerColumn.Header>
                                </UIGridColumnExtensions:TimePickerColumn>
                                <UIGridColumnExtensions:TimePickerColumn DataMemberBinding="{Binding EndTime}" TimeInterval="0:30:0" DataFormatString="{}{0:h:mm tt}">
                                    <UIGridColumnExtensions:TimePickerColumn.Header>
                                        <TextBlock Text="End Time" Foreground="White" />
                                    </UIGridColumnExtensions:TimePickerColumn.Header>
                                </UIGridColumnExtensions:TimePickerColumn>
                            </telerikGrid:RadGridView.Columns>
                        </telerikGrid:RadGridView>
                    </DataTemplate>
                </telerikGrid:RadGridView.HierarchyChildTemplate>
            </telerikGrid:RadGridView>

8 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 11 Jan 2011, 08:41 AM
Hello Nick Wood,

Based only on the code-snippet you provided, I am not able to find any possible cause of the issue you defined. Is there anything more specific that you do ? How do you handle the AddingNewDataItem event ? May you try to verify is the item is not added at all or it is moved to the bottom of the grid ?
Still, I am sending you a sample project implementing a similar scenario to yours. Please take a look at it and let me know in case of any discrepancies according to your requirements.
 

Kind regards,
Maya
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Nick Wood
Top achievements
Rank 1
answered on 11 Jan 2011, 09:26 AM
Hi Maya

Thanks for the same, the only issue is that the very same problem happens in the sample as well.

I have attached a file with 2 screens, the first is what is added as a new row, and the second is after I hit enter, the row just vanishes.

Below is the rowadded event as requested:
private void RadGridView1_AddingNewDataItem(object sender, Telerik.Windows.Controls.GridView.GridViewAddingNewEventArgs e)
        {
            e.NewObject = this.VM.NewProfileDay();
        }

And from the viewmodel:
public SiteProfileDays NewProfileDay()
        {
            SiteProfileDays profileDay = new SiteProfileDays();
            profileDay.SiteProfileId = this.EditSiteProfile.SiteProfileId;

            return profileDay;
        }


Thanks for your help.

Nick
0
Nick Wood
Top achievements
Rank 1
answered on 11 Jan 2011, 09:37 AM
Further Information:
If I manually add the new object to the EntitySet that is the ItemsSource for the grid as per the modified code below, There are 2 new rows added, the one that I am modifying and one that is the same object so updated as I enter information into the new row are shadowed on the extra row. but after I press enter, the row I am adding is gone as before, but the shadow row that I manually added to the EntitySet remains in the grid.

public SiteProfileDays NewProfileDay()
        {
            SiteProfileDays profileDay = new SiteProfileDays();
            profileDay.SiteProfileId = this.EditSiteProfile.SiteProfileId;
            this.SiteProfileDaysList.Add(profileDay);

            return profileDay;
        }


So it would seem that the new object is not being attached to the ItemsSource EntitySet.

Nick
0
Maya
Telerik team
answered on 11 Jan 2011, 09:39 AM
Hi Nick Wood,

I have re-tested the sample I previously attached and once an item is added and the changes are committed, this particular item goes either in the last position (in the last row) or in the appropriate place depending on the sorting state. So, if no sorting is applied, the newly-added item will be added in the end. If the ShipCity property is defined as "WWW" and the column is sorted in descending order, this item will be insert in the beginning. 

Greetings,
Maya
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Nick Wood
Top achievements
Rank 1
answered on 11 Jan 2011, 12:26 PM
Hi Maya

ok, I see the difference in the code, you are using EntitySetCollectionView

I have implimented the same collection and bound to that collection and it works well. The issue that I have is that how do I navigate from this to child objects in a HierarchyChildTemplate template? I would normally just bind to the navigation objects from the parent entity.

In your example you have Orders and Order Details, but the child object query just returns all objects, not just the objects that are related to the parent record.

Please help

Nick

0
Maya
Telerik team
answered on 11 Jan 2011, 03:47 PM
Hi Nick Wood,

Following up the sample attached previously, you may define the ParentPropertyName in the definition of the Relation in the GridViewChildTableDefinition:

<telerik:RadGridView.ChildTableDefinitions>
   <telerik:GridViewTableDefinition>
    <telerik:GridViewTableDefinition.Relation>
        <telerik:PropertyRelation ParentPropertyName="Order_Details" />
    </telerik:GridViewTableDefinition.Relation>
   </telerik:GridViewTableDefinition>
</telerik:RadGridView.ChildTableDefinitions>

However, you need to make sure that the Order_Details are loaded. You may do that in the invocation of the Orders for example:
public IEnumerable Orders
{
    get
    {
        if (this.orders == null)
        {
            this.orders = new EntitySetCollectionView<Order>(this.context.Orders);
        this.context.Load(this.context.GetOrdersQuery());                                  this.context.Load(this.context.GetOrder_DetailsQuery());
        }
       return orders;
    }
}

Another possible approach may be to use the RadDomainDataSource control, which will be released together with our Service Pack in a couple of days. By using it, you will not need to put into usage the EntitySetCollectionView. However, you may test it by downloading the binaries from our Latest Internal Build. Furthermore, you may take a look at this series of blog posts for a reference.
 

Kind regards,
Maya
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Jonx
Top achievements
Rank 2
answered on 18 Jan 2011, 04:26 PM
Hello Nick,
Just wondering something if my solution can help you.

It just happens that I had the exact same problem then you describe.
I clicked in "insert new row", filled out the fields, pressed return and the row and its values just vanished with no errors.

I had the intuition that something was missing in my entity. My entity has an Id that is a Guid.
The way I solved it was to override the entity creation in the silverlight project and set a new guid to replace the empty guid my ID had by default (despite the fact that I set the ID to newguid on the server side).

Maybe this can solve your initial problem too or at least it will serve me as a record for the future ;)

using System;
 
namespace MyTool.Web
{
    public partial class Client
    {
        partial void OnCreated()
        {
            this.CliID = Guid.NewGuid();
        }
    }
}

;)
John.
0
Jonx
Top achievements
Rank 2
answered on 27 Apr 2011, 04:25 AM
Nick? Have you solved your issue? I guess so.
Just you know, they were some issue in the grid causing me the exact same problem that were corrected in the latest builds...
John.
Tags
GridView
Asked by
Nick Wood
Top achievements
Rank 1
Answers by
Maya
Telerik team
Nick Wood
Top achievements
Rank 1
Jonx
Top achievements
Rank 2
Share this question
or