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

Crashing Winform after using RegEx in GridViewMaskBoxColumn

5 Answers 75 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Andreas
Top achievements
Rank 1
Andreas asked on 09 Sep 2014, 01:46 PM
Hello to all!

I've a GridViewMaskBoxColumn, where float are displayed using the exponental notation.  When I try to change a cells value, I can put the wished values, but when I leave the editor, the application crashs (even if I put only a '0')

The crash happens immediately after leaving the 'CellEndEdit'.

What went wrong in my source?

Thanks for your help!




   
   System.NullReferenceException wurde nicht behandelt.
  Message=Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.
  Source=Telerik.WinControls.UI
  StackTrace:
       bei Telerik.WinControls.UI.RegexMaskTextBoxProvider.KeyDown(Object sender, KeyEventArgs e)
       bei Telerik.WinControls.UI.RadMaskedEditBoxElement.TextBoxItem_KeyDown(Object sender, KeyEventArgs e)
       bei System.Windows.Forms.KeyEventHandler.Invoke(Object sender, KeyEventArgs e)
       bei Telerik.WinControls.RadItem.OnKeyDown(KeyEventArgs e)
       bei Telerik.WinControls.UI.RadTextBoxItem.TextBoxControl_KeyDown(Object sender, KeyEventArgs e)
       bei System.Windows.Forms.Control.OnKeyDown(KeyEventArgs e)
       bei System.Windows.Forms.Control.ProcessKeyEventArgs(Message& m)
       bei System.Windows.Forms.Control.ProcessKeyMessage(Message& m)
       bei System.Windows.Forms.Control.WmKeyChar(Message& m)
       bei System.Windows.Forms.Control.WndProc(Message& m)
       bei System.Windows.Forms.TextBoxBase.WndProc(Message& m)
       bei System.Windows.Forms.TextBox.WndProc(Message& m)
       bei Telerik.WinControls.UI.HostedTextBoxBase.WndProc(Message& message)
       bei System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       bei System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       bei System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       bei System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       bei System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
       bei System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       bei System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       bei System.Windows.Forms.Application.Run(Form mainForm)
       bei Maxsyma.PLCExplorer.Program.Main() in e:\...\SourceCode\Regex\Program.cs:Zeile 40.
  InnerException:



Here is my code:

private void InitializeGrid()
{
..
    newColumn = new GridViewMaskBoxColumn();    // for float
    newColumn.Name = "Gleitpunkt";
    newColumn.TextAlignment = ContentAlignment.MiddleRight;
    newColumn.Width = 60;
    newColumn.HeaderText = "Gleitpunkt";
    newColumn.FormatString = "{0:0.000000e0}";
    this.radGridViewCapture.Columns.Add(newColumn);
..
}

private void CellBeginEdit(object sender, GridViewCellCancelEventArgs e)
{
    if (this.radGridViewCapture.ActiveEditor is RadMaskedEditBoxEditor)
    {
        RadMaskedEditBoxEditor spinEditor = this.radGridViewCapture.ActiveEditor as RadMaskedEditBoxEditor;
        spinEditor.EditorElement.Alignment = ContentAlignment.MiddleCenter;
        spinEditor.EditorElement.StretchVertically = false;
        this.radGridViewCapture.CurrentCell.Alignment = ContentAlignment.MiddleCenter;
    }
}

private void CellEditorInitialized(object sender, GridViewCellEventArgs e)
{
    if (this.radGridViewCapture.ActiveEditor is RadMaskedEditBoxEditor)
    {
        RadMaskedEditBoxEditor spinEditor = this.radGridViewCapture.ActiveEditor as RadMaskedEditBoxEditor;
        if (e.Column.Name == ColumnName.Names[ColumnName.ResultGleitpunkt])
        {
            spinEditor.MaskTextBox.MaskType = MaskType.Regex;
            spinEditor.MaskTextBox.Mask = "[-+]?([0-9]*[,.])?[0-9]+([eE][-+]?[0-9]+)?"; // e.g. 123.4e+5
        }
    }
}

private void CellEndEdit(object sender, GridViewCellEventArgs e)
{
    if (e.Column.Name == "Gleitpunkt")
    {
        float myNewValue = float.Parse(e.Row.Cells[e.ColumnIndex].Value.ToString());
        
        // myNewValue is e.g. 0 or  123  or  123.4e-88 and is correct so far
    }
}            




5 Answers, 1 is accepted

Sort by
0
George
Telerik team
answered on 12 Sep 2014, 12:58 PM
Hello Andreas,

Thank you for writing.

The problem in this case is the way you are parsing the value of the cell in the CellEndEdit handler. There are cases where the value can be null or different than a number. You need to safely create a string, even if the value is null and then use the TryParse method:
void Grid_CellEndEdit(object sender, GridViewCellEventArgs e)
{
    if (e.Column.Name == "Gleitpunkt")
    {
        string value = e.Row.Cells[e.ColumnIndex].Value + "";
        float floatValue;
        if (float.TryParse(value, out floatValue))
        {
            //do some logic with floatValue
        }
    }
}

I hope this helps.

Regards,
George
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Andreas
Top achievements
Rank 1
answered on 12 Sep 2014, 04:14 PM
Hello George,

thanks for answer. I tried out your changes, but it does not help - the application crashs in the same way like before, even when I include all the lines in a try-catch block. The fault does not occure in  Grid_CellEndEdit()

I've also included a try-catch blocks mostly all methods - no success to catch the fault...
I've also deactivated writing to this cell, even to the completely grid .. same problem.

I only have one (main-)thread running, but it seems to me as it is something like a synchronisation fault? Maybe it help when I switch off updating the grid, preventing the grid to handle more events..? How can I do this?

Regards
andreas
0
George
Telerik team
answered on 17 Sep 2014, 11:32 AM
Hello Andreas,

Thank you for writing.

I can confirm that there is an exception when the regex mask is used. The issue is already logged and can be found on the following address: UI for Winforms Feedback Portal - FIX. RadGridView - GridViewMaskBoxColumn with regex mask throws an exception upon validation. Due to the nature of the issue I cannot provide you with a workaround for the time being. You can wait for our next release 2014 Q3 which will include the fix for this matter.

Let me know, should you have other questions.

Regards,
George
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Andreas
Top achievements
Rank 1
answered on 23 Sep 2014, 12:55 PM
Hello George,

Thank you for your anwer. It's good to know, that the problem it is not in my code, in the installation or in my PC...
It's not a problem for me to wait until the new release. Meanwhile I'll not use the regex und verify the result by my code.

Would be fine, if it will work in the Q3.

Regards,

Andreas
0
George
Telerik team
answered on 25 Sep 2014, 03:19 PM
Hello Andreas,

I am glad that this issue is not a deal breaker and that it is okay to wait for the next release.

Should you have any further questions, do not hesitate to let me know.

Regards,
George
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
GridView
Asked by
Andreas
Top achievements
Rank 1
Answers by
George
Telerik team
Andreas
Top achievements
Rank 1
Share this question
or