Wednesday, 10 December 2014

Introduction

In telerik WPF radgridview, when we apply grouping, we can find that some groups will automatically expand even if there is no user interaction. This mostly happens in scenario when there is some value change in rows which are grouped. This will also happen in other scenarios as well. This is a known bug in telerik radgridview at the time when this post is posted.
In this post you will find out how to block this bug with the help of a custom behavior. Here we will make use of mouse click event and GroupRowIsExpandedChanging events. Here subscribing to mouse click events may look tricky; in order to understand this, you have to refer to this post.

Introduction


In this post, we will find out how to find the group, if grouping is applied on the radgridview, in which the event occurred. Or how to find if the row clicked is group row or not.

If you have subscribed to the mouse click event properly, you will get call to the delegate which is registered to the click event. You can refer to this post for proper subscription of mouse click event.

Now if you are getting calls to the delegate, then it is easy to find the row in which the event occurred, you can refer to this post to find out how you can achieve this.

Now to find out how to find the group in which this event occurred, you have to do something like this as shown below.

How to achieve this?

private void GridViewRowMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
 {
   var senderElm = e.OriginalSource as FrameworkElement;
   var currentRow = senderElm.ParentOfType<GridViewRow>();
   var parentGroup = senderElm.ParentOfType<GridViewGroupRow>();

   if (currentRow == null && parentGroup != null)
    {
       // clicked on grouped row.
    }

   if (currentRow != null)
    {
      // clicked on a row.
    }
}
Introduction

If you are able to subscribe to a mouse click event on a radgridView, then your immediate requirement could be to find the row in which the mouse click event occurred. In this post we will see how to achieve this. If you are not subscribing to mouse click event properly, then you can refer to this post.