"Exception thrown: 'System.NullReferenceException' in Telerik.WinControls.GridView.dll".

9 posts, 1 answers
  1. Myo
    Myo avatar
    7 posts
    Member since:
    Sep 2016

    Posted 01 Nov Link to this post

    I'm using Telerik.WinControls.GridView version 2012.2.912.40.

    I validate a cell value in cell validating event.

    I set e.Cancel = true in CellValidating event and then delete row of that cell with a command cell click event.

    when the gridview's row count reach to zero and double click the gridview error occur "Exception thrown: 'System.NullReferenceException' in Telerik.WinControls.GridView.dll".

    private void gvStockItemDetail_CellValidating(object sender, CellValidatingEventArgs e)
    {

     if (!string.IsNullOrEmpty(Convert.ToString(e.Row.Cells["Stock ID"].Value)) && column.Name == "Quantity")
      {
        if (Convert.ToDecimal(string.IsNullOrEmpty(Convert.ToString(e.Value)) ? 0 : e.Value) <= 0)
         {
           e.Cancel = true;
           e.Row.Cells["Quantity"].BeginEdit();
           e.Row.ErrorText = BOL_Global_Message.STOCK.Msg_Quantity;                      
         }
        else
         {
           e.Row.ErrorText = string.Empty;
         }
       }

    }

    private void gvStockItemDetail_CommandCellClick(object sender, EventArgs e)
    {
       if (gvStockItemDetail.CurrentRow.Index >= 0)
       {
        gvStockItemDetail.Rows.RemoveAt(gvStockItemDetail.CurrentRow.Index);

       }

    }

  2. Dimitar
    Admin
    Dimitar avatar
    1415 posts

    Posted 02 Nov Link to this post

    Hello Myo,

    Thank you for writing.

    Following your description, I have created a small test project however I cannot reproduce the exception. Could you please check the project and let me know what I need to change in order to reproduce this?

    I am looking forward to your reply.
     
    Regards,
    Dimitar
    Telerik by Progress
    Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Myo
    Myo avatar
    7 posts
    Member since:
    Sep 2016

    Posted 04 Nov Link to this post

    Hello Dimitar,

    I make some changes to your sample and test it.

    I found error . I delete a record to set e.Cancel = true; on a cell and then delete all rows of the grid.

    When all row records clear and make a click on Delete column's header text.

    Then I make double click on the blank of the grid.

    It is occurs.

    Please see my link. I can't attach the project.

    https://drive.google.com/open?id=0BzxUL26eMScAMTc4aGVrV3VUZVk

    Regards

    Myo

  5. Dimitar
    Admin
    Dimitar avatar
    1415 posts

    Posted 04 Nov Link to this post

    Hello Myo,

    I have tested this but still there is no exception on my side. I have recorded a small video that shows what I am doing. Could please check it and let me know what else needs to be done?

    In addition, could you please specify which version you are using?

    I am looking forward to your reply.
     
    Regards,
    Dimitar
    Telerik by Progress
    Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
  6. Myo
    Myo avatar
    7 posts
    Member since:
    Sep 2016

    Posted 04 Nov Link to this post

    Hi Dimitar,

    I have seen this.

    I'm using version 2012.2.912.40.

    Please make a cell to it's e.Cancel value true; and then delete row without changes e.Cancel's value.

    eg. Delete a cell's content which validate in cell validation event and press enter key to set e.Cancel's value true.

    I think error occurs due to missing cell which has e.Cancel value true. Because we delete it and when gridview's row count is zero and double click grid.

    Regards,

    Myo

  7. Answer
    Dimitar
    Admin
    Dimitar avatar
    1415 posts

    Posted 07 Nov Link to this post

    Hello Myo,

    I was able to reproduce the exception, it is caused because the current cell of the grid is null when the grid is double clicked. To avoid this you need to create a custom class that inherits RadGridView and override the OnMouseDoubleClick method:
    class MyGrid : RadGridView
    {
        protected override void OnMouseDoubleClick(MouseEventArgs e)
        {
            if (this.CurrentCell == null)
            {
                return;
            }
     
            base.OnMouseDoubleClick(e);
        }
    }

    I hope this will be useful. Let me know if you have additional questions.

    Regards,
    Dimitar
    Telerik by Progress
    Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
  8. Myo
    Myo avatar
    7 posts
    Member since:
    Sep 2016

    Posted 08 Nov Link to this post

    Hi Dimitar,

    I added new class like the following.

    Show error 'MyGrid.OnMouseDoubleClick(MouseEventArgs)': no suitable method found to override.

    Please help me.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Telerik.WinControls.UI;
    using Telerik.WinControls;
    using Telerik.WinControls.Data;

    namespace TestingProject
    {
        class MyGrid : RadGridView
        {
            protected override void OnMouseDoubleClick(MouseEventArgs e)
            {
                if (this.CurrentCell == null)
                {
                    return;
                }

                base.OnMouseDoubleClick(e);
            }
        }

    }

     

    Regards,

    Myo

  9. Dimitar
    Admin
    Dimitar avatar
    1415 posts

    Posted 08 Nov Link to this post

    Hello Myo,

    Please make sure that your project references all needed Telerik assemblies and the System.Windows.Forms.dll assembly. 

    Should you have any other questions do not hesitate to ask.

    Regards,
    Dimitar
    Telerik by Progress
    Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
  10. Myo
    Myo avatar
    7 posts
    Member since:
    Sep 2016

    Posted 08 Nov in reply to Myo Link to this post

    Hi Dimitar,

    It is ok.

    Thank you a lot.

    Regrads,

    Myo

Back to Top
UI for WinForms is Visual Studio 2017 Ready