PART I [example: Adding an ‘Insert new row’ button to RadGridView ] 

Certain scenarios require adding additional behaviors and/or visuals to RadGridView. Implementing these as integrated features in RadGridView is not always appropriate as they may serve quite specific client scenarios or may require customization beyond the power of a common integrated feature.

According to the canons of WPF and Silverlight such tasks should be easily achieved by modifying the default control template and adding the necessary visuals (e.g. user controls with some additional logic included).

My experience with clients shows that such approach is sometimes kind-of frustrating as it often involves re-pasting large blocks of obfuscated XAML. I have been often asked if a single-line-of-code approach in certain scenario is possible.

In my following posts I am going to demonstrate how attached behaviors may be useful in cases where RadGridView needs a bit more functionality than provided out-of-the box.

For example – when  building UI to allow user to insert new row the typical approach would be to add a button besides the grid and call RadGridView.BeginInsert() within the button click event  handler.

However many developers prefer to add an ‘Insert new row’ button within the visual structure of the RadGridVIew rather than placing an external button besides.

Something like:

insert_new_screenshot

Adding the button with the add-new-row behavior should be as easy as adding a few lines of XAML:

   1: <telerik:RadGridView x:Name="RadGridView1" >
   2: <i:Interaction.Behaviors>
   3: <behavior:AddNewRowBehavior/>
   4: </i:Interaction.Behaviors>
   5: </telerik:RadGridView>

 

To have this working you will need to paste the AddNewRowBehavior.cs  to your project as well as a reference to System.Windows.Interactivity assembly. Both you can find in 

.

 

You may notice that for the purposes of illustration and brevity  I create some buttons in code . If you decide to use this code in your project I would highly recommend to use an user control instead. This will give you an easy way to style it (e.g. colorize or add an image) .

 

In my next post I will demonstrate how to add some client side printing power to RadGridView for Silverlight …


Related Posts

Comments

Comments are disabled in preview mode.