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

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

8 Answers 483 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Missing User
Missing User asked on 18 Jan 2013, 11:09 AM
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>

8 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 18 Jan 2013, 02:51 PM
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.

0
Missing User
answered on 21 Jan 2013, 01:42 AM
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 ?
0
Dimitrina
Telerik team
answered on 21 Jan 2013, 01:31 PM
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.

0
Missing User
answered on 22 Jan 2013, 10:41 AM
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.
0
Dimitrina
Telerik team
answered on 22 Jan 2013, 01:54 PM
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.

0
Missing User
answered on 23 Jan 2013, 01:52 AM
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.
0
Dimitrina
Telerik team
answered on 24 Jan 2013, 08:23 AM
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.

0
Thomas
Top achievements
Rank 1
answered on 28 May 2015, 12:12 PM

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

Tags
GridView
Asked by
Missing User
Answers by
Dimitrina
Telerik team
Missing User
Thomas
Top achievements
Rank 1
Share this question
or