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

OverflowException on keypress with special characters

4 Answers 178 Views
GridView
This is a migrated thread and some comments may be shown as answers.
FilipN
Top achievements
Rank 1
FilipN asked on 23 Jul 2009, 08:12 AM
Hello,
I have encountered this exception when handling KeyPress event. I am from Czech Republic and we have specific characters, for example: ˇ - it's KeyChar 711 (examining KeyPressEventArgs in standard GridView control which lacks the bug). However when trying to type this character on RadGridView the exception is thrown.

The only solution that I can think of right now is overriding PreProcessMessage or ProcessDialogKey on RadGridView subclass - so not allowing the characters to be passed to the application (so as not to get the exception) I have not try it just yet though.

System.OverflowException was unhandled
  Message="Value was either too large or too small for an Int32."
  Source="mscorlib"
  StackTrace:
       v System.Convert.ToChar(Int32 value)
       v Telerik.WinControls.UI.BaseGridBehavior.ProcessAlphaNumericKey(KeyEventArgs keys)
       v Telerik.WinControls.UI.BaseGridBehavior.ProcessKey(KeyEventArgs keys)
       v Telerik.WinControls.UI.RadGridView.ProcessDialogKey(Keys keyData)
       v System.Windows.Forms.Control.PreProcessMessage(Message& msg)
       v System.Windows.Forms.Control.PreProcessControlMessageInternal(Control target, Message& msg)
       v System.Windows.Forms.Application.ThreadContext.PreTranslateMessage(MSG& msg)
       v System.Windows.Forms.Application.ThreadContext.System.Windows.Forms.UnsafeNativeMethods.IMsoComponent.FPreTranslateMessage(MSG& msg)
       v System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
       v System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       v System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       v System.Windows.Forms.Application.Run(Form mainForm)
       v WindowsFormsApplication2.Program.Main() v C:\Users\nguyen\Documents\Visual Studio 2008\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Program.cs:řádek 18
       v System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       v System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       v Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       v System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       v System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       v System.Threading.ThreadHelper.ThreadStart()
  InnerException:

4 Answers, 1 is accepted

Sort by
0
Accepted
Jack
Telerik team
answered on 23 Jul 2009, 12:40 PM
Hello Filip Nguyen,

I was not able to reproduce the issue. However, the best approach to intercept keyboard events in RadGridView is to replace the default GridBehavior. Here is a sample:

this.radGridView1.GridBehavior = new MyBehavior(); 
 
public class MyBehavior : BaseGridBehavior 
    public override bool ProcessKeyDown(KeyEventArgs keys) 
    { 
        // ... 
        return base.ProcessKeyDown(keys); 
    } 

I hope this helps. If the issue continues to re-appear please send us your application and we will try to locate and address it. I am looking forward to your reply.

Sincerely yours,
Jack
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Mydatafactory
Top achievements
Rank 1
answered on 09 Feb 2010, 02:50 PM
Hello,

I am having the same problem. We have a RadGridView on a (non-Telerik) form. We catch keypress events on the form level (form.KeyPress). The event is first catched by the RadGridView, which should then pass it on to the form. But there the error occurs.

We tested a little and found the following: if we set the keyboard regional setting to 'English (US) - United States', there is no problem. If we however set the keyboard to 'English (US) - International', the error occurs. I think this may have to do with different character encodings (unicode?).

Your suggestion of a custom grid behavior does not work: the error occurs before it gets there. In case of the keyboard setting 'English US - International' the character is (I think) of another character encoding and the charactercode is larger than an Int32, and converting it to a char (for in the eventargs) fails.

Could you confirm this and (if so), do you have a work-around for this? Thanks in advance for the answer.
0
Mydatafactory
Top achievements
Rank 1
answered on 09 Feb 2010, 02:58 PM
To clarify a bit further: the error occurs with characters like ~ and `, when the keyboard setting is 'English (US) - International'.
0
Jack
Telerik team
answered on 11 Feb 2010, 11:46 AM
Hello A.,

Thank you for contacting us. As previously proposed in this thread, you should replace the default grid behavior and handle this case manually in ProcessKeyDown method. We will address the issue in one of our upcoming releases.

Greetings,
Jack
the Telerik team

Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
Tags
GridView
Asked by
FilipN
Top achievements
Rank 1
Answers by
Jack
Telerik team
Mydatafactory
Top achievements
Rank 1
Share this question
or