Adding a NewRow by code (ria) and Required Values

4 posts, 0 answers
  1. Iosu Buenetxea
    Iosu Buenetxea avatar
    91 posts
    Member since:
    Jan 2008

    Posted 23 Mar 2010 Link to this post

    Hi,,

    I have a GridView binded to a DomainDataSource..(RIA)
    <telerikGridView:RadGridView ItemsSource="{Binding ElementName=UNIDADDomainDataSource, Path=Data}" 


    I have also a Field that I have declared as "Required" but is not showed as a column on the GRID so the validation of a new row always fails.

    So one of the solution is to add a new row manualy:

     

     Private Sub NewRecord_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)  
            UNIDADRadGridView.IsReadOnly = False 
            UNIDADRadGridView.BeginInsert() 

    and then on the AddingNewDataItem set the default valued for the required Field:

     

     Private Sub UNIDADRadGridView_AddingNewDataItem(ByVal sender As Object, ByVal e As Telerik.Windows.Controls.GridView.GridViewAddingNewEventArgs) Handles UNIDADRadGridView.AddingNewDataItem  
            Dim newUnidad As New UNIDAD()  
            newUnidad.CODEMP = "1" 
            e.NewObject = newUnidad 
        End Sub 
    The problem is that it does not add a new row on the grid.. (If I remove the e.newObject=NewUnidad I can see a new empty row)
    Is this a Bug? Or I'm doing something wrong?

    Also, Do you see another solution for "Required" Fields on RIA ???

    I'm using SL4 with RadControls 00478RadControls_for_Silverlight4RC_2010_1_0319_Dev

    Thanks!

  2. Stefan Dobrev
    Admin
    Stefan Dobrev avatar
    790 posts

    Posted 23 Mar 2010 Link to this post

    Hello JUAN CRESPO,

    The solution to the adding new item with required field is to override the partial method OnCreated() for your entity on the client. This partial method is generated by RIA Services for you and will be called whenever a new object is created on the client. In this method you can set your required field to some valid value.

    Hope this helps,
    Stefan Dobrev
    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.
  3. DevCraft banner
  4. Iosu Buenetxea
    Iosu Buenetxea avatar
    91 posts
    Member since:
    Jan 2008

    Posted 23 Mar 2010 Link to this post

    OK, so if my entity name is "UNIDAD" I have to create  a new clase on the SL proyect and add:

    Imports System.ServiceModel.DomainServices.Client

    Namespace MSPLite.Web

        Partial Public Class UNIDAD

            Inherits Entity

            Private Sub OnCreated()

                 Me.CODEMP = "1"

            End Sub

        End Class

    End Namespace

     

     

     

     

     

    This gives me a lot of error on for the LoginForm.. etc... (I'm using the Business SL Template), ............
    EDIT I made it work.. I changed :
    TO 

    Imports System.ServiceModel.DomainServices.Client

    Imports MSPLite.Web

        Partial Public Class UNIDAD

            Inherits Entity

            Private Sub OnCreated()

                 Me.CODEMP = "1"

            End Sub

        End Class

     

     

     

    I have remove the Namespace and Imports the web project, and NOW is working..

    But I still have some question
    why  <DefaultValue ("0")>  is not working ??? Because <required> etc are working...(I prefer to set this attibutes on the DomainService Metadata on the web part..

    and also:
    Why the code below does not create a new row?

    Private Sub UNIDADRadGridView_AddingNewDataItem(ByVal sender As Object, ByVal e As Telerik.Windows.Controls.GridView.GridViewAddingNewEventArgs) Handles UNIDADRadGridView.AddingNewDataItem  
            Dim newUnidad As New UNIDAD()  
            newUnidad.CODEMP = "1" 
            e.NewObject = newUnidad 
        End Sub 


    Thank you for your help...

  5. Stefan Dobrev
    Admin
    Stefan Dobrev avatar
    790 posts

    Posted 24 Mar 2010 Link to this post

    Hi JUAN CRESPO,

    I'm not aware why the DefaultValueAttribute is not working. Maybe you should ask this on RIA Services forum threads.

    Regarding your other question the provided code snippets is not working, because the underlying collection that RadGridView is bound to - DomainDataSourceView do not implement ICollection, thus we cannot add items to it. In order to make this work you can use this code snippet:
    Private Sub UNIDADRadGridView_AddingNewDataItem(ByVal sender As Object, ByVal e As GridViewAddingNewEventArgs) Handles UNIDADRadGridView.AddingNewDataItem 
            Dim newUnidad As New UNIDAD() 
            newUnidad.CODEMP = "1"
            e.NewObject = newUnidad
            'Use your DomainDataSource here
            UNIDADDomainDataSource.DataView.Add(e.NewObject)
    End Sub


    Hope this helps,
    Stefan Dobrev
    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.
Back to Top