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

Exceptions when overriding row behavior processkey methods

6 Answers 148 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Brian Manning
Top achievements
Rank 1
Brian Manning asked on 26 Oct 2010, 11:01 PM
Hi there,

My users want me to change the default key navigation behavior on a hierarchical grid.  For instance, they want the tab key to move down to the children of a hierarchical row if it's the end of the line instead of moving to the next row of the same level.

I implemented a solution that looks like this:

public class CustomGridHierarchyRowBehavior : GridHierarchyRowBehavior
{
    protected override bool ProcessTabKey(KeyEventArgs keys)
    {
        if (GridViewElement.Navigator.IsLastColumn(GridViewElement.CurrentColumn) && !keys.Shift)
        {
            GridViewElement.Navigator.Select(GridViewElement.CurrentRow.ChildRows[0], GridViewElement.CurrentRow.ChildRows[0].ViewTemplate.Columns[0]);
            return true;
        }
  
        return base.ProcessTabKey(keys);
    }
}

But I get the following exception sometimes when tabbing around quickly:

Object reference not set to an instance of an object.
   at Telerik.WinControls.UI.ViewInfoTraverser.SetCollectionForStage()
   at Telerik.WinControls.UI.ViewInfoTraverser.Reset()
   at Telerik.WinControls.UI.ViewInfoTraverser..ctor(GridViewInfo viewInfo)
   at Telerik.WinControls.UI.GridRowBehavior.IsOnLastCell()
   at Telerik.WinControls.UI.GridRowBehavior.ProcessTabKey(KeyEventArgs keys)
   at MyApp.CustomGridHierarchyRowBehavior.ProcessTabKey(KeyEventArgs keys) in C:\Dev\MySolution\MyApp\App_Code\CustomGridView.cs:line 141
   at Telerik.WinControls.UI.GridRowBehavior.ProcessKey(KeyEventArgs keys)
   at Telerik.WinControls.UI.BaseGridBehavior.ProcessKey(KeyEventArgs keys)
   at Telerik.WinControls.UI.RadGridView.ProcessDialogKey(Keys keyData)
   at System.Windows.Forms.Control.PreProcessMessage(Message& msg)
   at System.Windows.Forms.Control.PreProcessControlMessageInternal(Control target, Message& msg)
   at System.Windows.Forms.Application.ThreadContext.PreTranslateMessage(MSG& msg)
   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at MyApp.Program.Main() in C:\Dev\MySolution\MyApp\Program.cs:line 20

The line 141 in my custom method correlates to the call to "return base.ProcessTabKey(keys);".

Am I doing something wrong?  Am I missing an important call to some helper method or forgetting to set some property?  I've been experimenting with these behavior classes and have been having a lot of trouble with random/difficult to reproduce exceptions deep inside the guts of the grid.

I should also probably mention that my grid is three levels deep, in case that makes any difference (as it did for the issue with collapsing hierarchy rows).  And I'm using VS 2008 and version 2010.2.10.914 of the Telerik controls.

Thanks for any insight!

6 Answers, 1 is accepted

Sort by
0
Brian Manning
Top achievements
Rank 1
answered on 27 Oct 2010, 06:10 PM
Never mind, I guess.  It has nothing to do with overriding the ProcessKey method, and everything to do with tabbing/arrowing around on cells that aren't scrolled into view.  I'll be submitting a bug report shortly.
0
Emanuel Varga
Top achievements
Rank 1
answered on 27 Oct 2010, 09:52 PM
Hello Brian,

I would suggest a possible workaround but i didn't have time to test it yet.
If this is caused by your code you could always check the visibility of the cell (before selecting it) or you could expand it if it is not expanded.
Please let me know how it goes, and i will try to test it for myself as soon as i can.

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga
0
Brian Manning
Top achievements
Rank 1
answered on 27 Oct 2010, 11:05 PM
Hey Emanuel,

Thanks for the reply.  I have my doubts that you'll be able to reproduce the error though.  I've been having a heck of a time trying to reproduce it in a test project.

A couple of things though if you decide to keep on:

-It's not a matter of the rows not being expanded.  I run a recursive routine to expand all of my rows when the grid loads.
-It's not my code (or at least not directly).  It seems to come straight through the regular GridHierarchyRowBehavior.ProcessTab.  In my later experimenting I removed my ProcessTab override method entirely and it still occurred.  I would not be surprised if there's something else I'm doing in the way I'm loading or interacting with the grid that's indirectly causing it though.
-I've not found a way/method to make sure something is scrolled into view.  I've tried GridViewRowInfo.EnsureVisible(), but that does not seem to do a whole lot.  On the other hand, that could be related to the grid bug that's causing lots of extra whitespace when I use my ExpandAll method.

And actually now that I've tested some more I'm just getting lots of exceptions on the grid for larger sets of data.  I'm going to hit it tomorrow and see if I can throw together a test project that will reproduce some of it.  Otherwise my only hope would be that the Q3 release fixes some of these things.
0
Emanuel Varga
Top achievements
Rank 1
answered on 27 Oct 2010, 11:52 PM
Hello again Brian,

As soon as you have something please post a link if you can and i will be more than happy to take a look, hope we'll be able to fix all of those problems.

Best Regards,
Emanuel Varga
0
Brian Manning
Top achievements
Rank 1
answered on 29 Oct 2010, 07:31 PM
Hey Emanuel,

Thanks for the offer, but I ended up putting together a test project and submitting it to their PITS thing.  They confirmed the issues I was having and promised a fix next month.  Beyond that, I don't know that it'd be possible to work around the exceptions without inheriting the controls and overriding a substantial amount of their methods... which I'm already doing more than I'd like.

Thanks again, and have a great weekend!
0
Emanuel Varga
Top achievements
Rank 1
answered on 29 Oct 2010, 09:25 PM
Hello again Brian,

I'm glad to hear that they will fix these problems (I'm guessing in the Q3 release that is scheduled for mid November).

But like i said before if you need any more help just let me know.

Have a great weekend!

Best Regards,
Emanuel Varga
Tags
GridView
Asked by
Brian Manning
Top achievements
Rank 1
Answers by
Brian Manning
Top achievements
Rank 1
Emanuel Varga
Top achievements
Rank 1
Share this question
or