Don't Add New Row, on validation fails

2 posts, 0 answers
  1. crazy05
    crazy05 avatar
    74 posts
    Member since:
    Sep 2014

    Posted 20 May 2015 Link to this post

    I am using Interaction trigger on RowEditEnded. If the user enter invalid value, I want to remove that row from the Grid. How can I do this ?

    ItemsSource="{Binding ItemSource,Mode=TwoWay }"

     <i:Interaction.Triggers>
                        <i:EventTrigger EventName="RowEditEnded">
                            <cmd:EventToCommand Command="{Binding EditingCommand}" />
                        </i:EventTrigger>
                    </i:Interaction.Triggers>

     

     if (this.ItemSource.Count > 0)
                {
                    var newItem = this.ItemSource.FirstOrDefault(d => d.ItemOrder == null);

                    if (newItem != null)
                    {
                        if (newItem.Id > 0)
                        {
                           newItem .ItemOrder = this.ItemSource.Count;
                        }
                        else
                        {
                            this.ItemSource.Remove(newItem );
                        }   
                    }
                }

  2. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 22 May 2015 Link to this post

    Hi Ram,

    You have to work with the source collection that the grid is bound to. If you have ObservableCollection<Club> Clubs for example in your ViewModel that is the source of the grid, you can just remove the item from it and the grid will reflect the changes. 

    Regards,
    Maya
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
Back to Top