How to modify added object

9 posts, 1 answers
  1. Leos
    Leos avatar
    57 posts
    Member since:
    Jul 2010

    Posted 31 Mar 2011 Link to this post

    Hi,
    RadDataForm has event AddingNewItem.

    I tried add code to preset some values but I dont know how to get "added" object.

    private void RadDataForm_AddingNewItem(object sender, Telerik.Windows.Controls.Data.DataForm.AddingNewItemEventArgs e)
    {
        try
        {
            // Next line is without result, changes last record, not added
            //Produkt p = (Produkt)((RadDataForm)sender).CurrentItem;
            // Next line is returns  NULL and crash later
            //Produkt p = (Produkt) ProduktyDataSource.DataView.CurrentAddItem;
            // Next line without result, changes last record, not added
            //Produkt p = (Produkt)ProduktyDataSource.DataView.CurrentItem;                            
            Produkt p = ????????????;
            p.InsertDate = DateTime.Now;
        }
        catch(Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }

    Maybe AddedNewItem event is needed ??

    Note: I know that I can do this simple example in constructor of entity. But not all requirements  are so simple.

    PS: Telerik (generally) please add some real world LOB example for Silverlight and WCF.RIA.  With inserting, deleting,  filtering, master-details (order/items) processing, reporting. Some RAD style of data application. Your technology is great but I still have troubles to join all features together.
  2. Robert Kaucher
    Robert Kaucher avatar
    56 posts
    Member since:
    Oct 2010

    Posted 31 Mar 2011 Link to this post

    I agree with Leos on his final statement.

    I also had an issue with this as NewObject does not seem to exist in the Adding even. Interested in knowing how this might be done.
  3. DevCraft banner
  4. Answer
    Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 05 Apr 2011 Link to this post

    Hi guys ,

    Your request is absolutely reasonable.
    Currently  the event is fired just before the new object is created. This means the new object does not yet exist thus you are not able  to initialize it properly. So far the single purpose of the event is being able to cancel the adding of new item.
    I have consulted with the team and we have decided to schedule this for improvement. A reasonable timeframe  would be the very first Service Pack.

    Meanwhile here I may propose the following workaround :
    Subscribe to the CurrentItemChanged  event. Inside you may check if the event is invoked for a new item  and perform the initialization required.

    Best wishes,
    Pavel Pavlov
    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
  5. Luc
    Luc avatar
    1 posts
    Member since:
    Feb 2011

    Posted 28 Apr 2011 Link to this post

       Hello,

    Your workaround doesn't work for me. 
    My RadDataForm is bound to a List<Actor> . And I have to create either a Client or an Employee.
    Client and Employee are two classes that extends Actor.

    So, in the callback CurrentItemChanged, the currentItem is an Actor and I can't change it to a Client or an Employee. If I set the CurrentItem to a new Client or Employee, its value becomes null ...

    Do you have a workaround for me ?

       Thanks,
       Luc.
  6. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 29 Apr 2011 Link to this post

    Hi Luc ,

    I am afraid such implementation is not supported. The whole logic inside RadDataForm is based on the type of the source objects .
    When you feed it with List<Actor> it will not work correctly with inherited objects  -  Even if you somehow manage to add the inherited ( Employee)  class, you will be able to manipulate only the fields  - defined in the Actor class.

    Regards,
    Pavel Pavlov
    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
  7. tchapo
    tchapo avatar
    5 posts
    Member since:
    Jun 2011

    Posted 23 Aug 2011 Link to this post

    Hi there,

    I am encountering similar issue as Luc.

    I am trying to allow users to select a specific record and duplicate its values in a new row when the user clicks the add button.

    Has RadDataForm been improved in the Q2 2011 (version 2011.2.0712), so that we can initialize the new item properties before it is created?

    Using the workaround proposed on Apr 5, 2011, I am still confronted to the issue of getting the previous to current item; which I am unable to get. What I want for example is  the new currentitem “DocType” to be the same as the previous current “DocType” I can only hardcode some default values as in the code below.

    Here is my code

            void MyDataForm_CurrentItemChanged(object sender, EventArgs e)

            {

    if ((sender as RadDataForm).IsItemChanged && String.IsNullOrEmpty((this.MyDataForm.CurrentItem as MyDataServiceModels.ROWValidationError).Serial))

                {

    (this.MyDataForm.CurrentItem as MyDataServiceModels.ROWValidationError).DocType = "Master Title Plat";

                }

            }

    Thanks,

    Tchapo.

  8. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 29 Aug 2011 Link to this post

    Hi Tchapo,

    The feature will be present for the Service pack expected in around the middle of September.

    Kind regards,
    Pavel Pavlov
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

  9. Dan
    Dan avatar
    70 posts
    Member since:
    Mar 2007

    Posted 13 Sep 2011 Link to this post

    Hi

    I have same problem on WPF RadDataForm (I'm working with costom business objects). Your work-around is not working for me.
    Also Focus is not set on first TextBox when editing/adding.
    See below code:
    <UserControl x:Class="KMSConsole.ucQualities"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                 xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
                 MinHeight="261" MinWidth="547"
                 mc:Ignorable="d" d:DesignHeight="502" d:DesignWidth="547" Loaded="UserControl_Loaded">
        <UserControl.Resources>
            <ResourceDictionary>
                <ResourceDictionary.MergedDictionaries>
                    <ResourceDictionary Source="Styles\DataTemplates.xaml">
                    </ResourceDictionary>
                </ResourceDictionary.MergedDictionaries>
            </ResourceDictionary>
        </UserControl.Resources>
        <Grid Background="AntiqueWhite" HorizontalAlignment="Left" VerticalAlignment="Top">
            <Grid.RowDefinitions>
                <RowDefinition Height="auto" />
                <RowDefinition Height="*" />
                <RowDefinition Height="auto" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"  />
            </Grid.ColumnDefinitions>
            <StackPanel x:Name="spCommSettings">
                <telerik:RadDataForm x:Name="dfBeerTypeEditor" Header="beer type" AutoGenerateFields="False" DeletedItem="dfBeerTypeEditor_DeletedItem" DeletingItem="dfBeerTypeEditor_DeletingItem"
                                     EditTemplate="{StaticResource BeerTypeItemTemplate}"
                                     NewItemTemplate="{StaticResource BeerTypeItemTemplate}"
                                     ReadOnlyTemplate="{StaticResource BeerTypeItemTemplate}" SourceUpdated="dfBeerTypeEditor_SourceUpdated" AddingNewItem="dfBeerTypeEditor_AddingNewItem" EditEnding="dfBeerTypeEditor_EditEnding" CurrentItemChanged="dfBeerTypeEditor_CurrentItemChanged" />
            </StackPanel>
            <GroupBox x:Name="gbRecs" Header="top 20 records" Grid.Row="2" VerticalAlignment="Center"
                               Margin="4">
                <telerik:RadGridView x:Name="dgRecords" AutoGenerateColumns="False"
                                     CanUserReorderColumns="False"  IsFilteringAllowed="False" SelectionMode="Single"
                                     CanUserDeleteRows="True" CanUserInsertRows="True"
                                     Height="324" Width="528" BeginningEdit="dgRecords_BeginningEdit">
                    <telerik:RadGridView.Columns>
                        <telerik:GridViewDataColumn Header="name" UniqueName="Name" DataMemberBinding="{Binding Name}" Width="200" />
                        <telerik:GridViewDataColumn Header="price" UniqueName="Name" DataMemberBinding="{Binding Price}" DataFormatString="#9.99" Width="150" />
                    </telerik:RadGridView.Columns>
                </telerik:RadGridView>
            </GroupBox>
        </Grid>
    </UserControl>

    <DataTemplate x:Key="BeerTypeItemTemplate">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition/>
                <RowDefinition/>
            </Grid.RowDefinitions>
            <telerik:DataFormDataField Label="name" DataMemberBinding="{Binding Name, Mode=TwoWay}" />
            <telerik:DataFormDataField Grid.Row="1" Label="price" DataMemberBinding="{Binding Price, Mode=TwoWay}" />
        </Grid>
    </DataTemplate>


    public ucQualities()
    {
        InitializeComponent();         
        SetDataSources();
    }
     
    void SetDataSources()
    {
        List<BeerType> _bts = new List<BeerType>();
        _bts.Add(new BeerType { Id = 1, Name = "bt1" });
        _bts.Add(new BeerType { Id = 2, Name = "bt2" });
        _bts.Add(new BeerType { Id = 3, Name = "bt3" });
        _bts.Add(new BeerType { Id = 4, Name = "bt4" });
        _bts.Add(new BeerType { Id = 5, Name = "bt5" });
        _bts.Add(new BeerType { Id = 6, Name = "bt6" });
        dgRecords.ItemsSource = dfBeerTypeEditor.ItemsSource = CollectionViewSource.GetDefaultView(_bts);
    }

    Any thoughts?
    Thanks
  10. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 17 Sep 2011 Link to this post

    Hi guys,

    We are preparing an official service pack , which will be available for download the next week . We have added a new event to RadDataForm  - AddedNewItem. It is  the place where you can perform additional initialization for newly added items. You will have a direct access to the new object trough the event args.  I believe this will solve the issues.

    Best wishes,
    Pavel Pavlov
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top
DevCraft banner