how to add custom logic to add/delete/save button when using RadGridView(wpf)

9 posts, 0 answers
  1. Missing user
    Missing user avatar

    Posted 18 Jan 2013 Link to this post

    The demo(GridView.WPF.Commands)  is what we want. But when I write code , I find the command is bind to "telerikGrid:RadGridViewCommands.BeginInsert" , which is compiled into Telerik.Windows.Controls.dll. It is not a custom command in viewmodel. So how can I add my custom logic (such as save to database) to these command?

    your demo :
    <StackPanel Orientation="Horizontal"
                        HorizontalAlignment="Center"
                        Margin="0,5,0,0">
                <telerik:RadButton Width="150"
                                   Content="Delete selected rows"
                                   Margin="0,0,5,0"
                                   Command="telerikGrid:RadGridViewCommands.Delete"
                                   CommandTarget="{Binding ElementName=RadGridView1}" />
                <telerik:RadButton Width="150"
                                   Content="Add new row"
                                   Margin="0,0,5,0"
                                   Command="telerikGrid:RadGridViewCommands.BeginInsert"
                                   CommandTarget="{Binding ElementName=RadGridView1}" />
                <telerik:RadButton Width="150"
                                   Content="Save insert/edit"
                                   Margin="0,0,5,0"
                                   Command="telerikGrid:RadGridViewCommands.CommitEdit"
                                   CommandTarget="{Binding ElementName=RadGridView1}" />
                <telerik:RadButton Width="150"
                                   Content="Cancel insert/edit"
                                   Command="telerikGrid:RadGridViewCommands.CancelRowEdit"
                                   CommandTarget="{Binding ElementName=RadGridView1}" />
            </StackPanel>
  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 18 Jan 2013 Link to this post

    Hello,

    I am afraid that you cannot extend the built-in commands, but you could subscribe for the proper events raised on their execution. For example for the Delete command those will be the Deleting/Deleted events of the RadGridView. Once they are raised you could execute any additional logic. Do you think this would be a working solution for your scenario?

    Greetings,
    Didie
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. Missing user
    Missing user avatar

    Posted 20 Jan 2013 Link to this post

    Thx.
    How to bind event in MVVM? I find BeginEdit/Deleting/Deleted events,but no BeginInsert event.
    Could you provide a demo that I can run ?
  4. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 21 Jan 2013 Link to this post

    Hi,

    The event that corresponds to the BeginInsert command would be the AddingNewDataItem event of the RadGridView. You could use a WPF Attached Behavior for the GridView and handle the events that way.

    Kind regards,
    Didie
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  5. Missing user
    Missing user avatar

    Posted 22 Jan 2013 Link to this post

    Hi
    Our company buy telerik control to speed up development. We can implement the requirement without telerik. But since we have chosen telerik,  we want to use telerik in the right way. So a formal version demo is needed. And we need the demo to show two stages validation. First stage, the row is validated by viewmodel or something like validationRule. Second stage, the row is commited to database, database refuse it, we want the error message can show aside the row. It is a common scenario. Please provide sample.
  6. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 22 Jan 2013 Link to this post

    Hi,

    May I ask you to share a little bit more details on how do you connect/interact with the database? 

    Greetings,
    Didie
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  7. Missing user
    Missing user avatar

    Posted 22 Jan 2013 Link to this post

    As a demo, you can use any database, even a mock database is ok.  I want to see where I can replace your database logic code with  my logic code.  I want to use telerik in the best recommended way.
  8. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 24 Jan 2013 Link to this post

    Hi,

    Generally RadGridView supports various data validation methods like IDataErrorInfo + INotifyPropertyChanged, INotifyDataErrorInfo and DataAnnotation attributes. They provide information about errors and RadGridView will show "red borders" accordingly.

    You can validate on data level implementing INotifyDataErrorInfo interface for your ViewModel/business object. Please check this help article for details. Furthermore I have as well attached a sample project demonstrating such a validation (via INotifyDataErrorInfo). 

    All the best,
    Didie
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  9. Thomas
    Thomas  avatar
    31 posts
    Member since:
    Jun 2012

    Posted 28 May 2015 Link to this post

    Hi, its 2 years to late but maybe someone need them in future. 

    i think the answer about Events 2 Commands is given here

    http://docs.telerik.com/devtools/wpf/common-event-to-command-behavior.html

    br

Back to Top