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

Add new row with timestamp problem

2 Answers 30 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Babu Mannaravalappil
Top achievements
Rank 1
Babu Mannaravalappil asked on 24 Jan 2011, 07:36 PM
Hi,

I have a RadGridView, a RadDomainDataSource, a RIA DomainService and a .NET EntityFramework Model from my SQL database.  My grid works fine; it fetches the data and displays it in the grid as expected.  The underlying table for this Entity contains a non-nullable timestamp field by the name "Modified".  I don't want to show this field in the grid and so I did not create a grid column for it.  When I press the Insert key, as expected, a new blank row is inserted in the grid.  So far, so good.  But after filling the column values, and I press tab key to lose focus from the row, I get an error saying "The 'Modified' field is required".  How can I get rid of this error.  In other words, how would I go about validating the data to elimiate the error message.  Here is my XAML for the page.  Please advise.

<UserControl
    x:Class="Library.Views.Contributors"
    mc:Ignorable="d"
    d:DesignHeight="500"
    d:DesignWidth="700"
    xmlns:riaControls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.DomainServices"
    xmlns:my="clr-namespace:Library.Web.Model"
    xmlns:vm="clr-namespace:Library.ViewModels"
    xmlns:ds="clr-namespace:Library.Web.Model">
    <UserControl.Resources>
        <vm:ContributorListViewModel
            x:Key="ContributorsViewModel"
            xmlns:vm="clr-namespace:Library.ViewModels" />
    </UserControl.Resources>
  
    <Grid
        x:Name="LayoutRoot"
        Background="White">
        <Grid.ColumnDefinitions>
            <ColumnDefinition
                Width="0.731*" />
            <ColumnDefinition
                Width="0.269*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition
                Height="0.8*" />
            <RowDefinition
                Height="0.2*" />
        </Grid.RowDefinitions>
        <telerik:RadDomainDataSource
            x:Name="ContributorDS"
            QueryName="GetContributors"
            AutoLoad="True"
            PageSize="10"
            >
            <telerik:RadDomainDataSource.DomainContext>
                <ds:LibraryDataDomainContext />
            </telerik:RadDomainDataSource.DomainContext>
        </telerik:RadDomainDataSource>
        <telerik:RadBusyIndicator
            IsBusy="{Binding IsBusy, ElementName=ContributorDS}">
            <telerik:RadGridView
                Name="rgContributors"
                HorizontalAlignment="Stretch"
                ItemsSource="{Binding DataView, ElementName=ContributorDS}"
                IsBusy="{Binding IsBusy, ElementName=ContributorDS}" AutoGenerateColumns="False">
                <telerik:RadGridView.Columns>
                    <telerik:GridViewDataColumn
                        x:Name="PKId"
                        DataMemberBinding="{Binding PKId}"
                        Header="PKId"
                        UniqueName="PKId"
                        IsVisible="False" />
                    <telerik:GridViewDataColumn
                        x:Name="Name"
                        DataMemberBinding="{Binding Name}"
                        UniqueName="Name"
                        Width="3*"
                        Header="Name" />
                    <telerik:GridViewDataColumn
                        x:Name="Description"
                        DataMemberBinding="{Binding Description}"
                        UniqueName="Description"
                        Width="6*"
                        Header="Description" />
                </telerik:RadGridView.Columns>
            </telerik:RadGridView>
        </telerik:RadBusyIndicator>
    </Grid>
</UserControl>

Thanks.

Babu.

2 Answers, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 31 Jan 2011, 10:04 AM
Hello Babu Mannaravalappil,

You should handle the AddingNewDataItem event of RadGridView and set the timestamp property of the new object. You can find a sample project here.

Kind regards,
Veselin Vasilev
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
PMoransais
Top achievements
Rank 1
answered on 07 Oct 2011, 02:32 PM
The suggestion to provide a value for the timestamp field during row creation does not sound right: in SQLServer, fields of type timestamp are calculated by the database (Computed in Entity Framework). 

The only solution I can think of is to not include the field in the data set.That could present a problem in some scenarios

Thanks

Tags
GridView
Asked by
Babu Mannaravalappil
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
PMoransais
Top achievements
Rank 1
Share this question
or