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

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

8 Answers 853 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Myo
Top achievements
Rank 1
Myo asked on 01 Nov 2016, 05:43 AM

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);

   }

}

8 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 02 Nov 2016, 07:31 AM
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.
0
Myo
Top achievements
Rank 1
answered on 04 Nov 2016, 09:14 AM

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

0
Dimitar
Telerik team
answered on 04 Nov 2016, 11:52 AM
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.
0
Myo
Top achievements
Rank 1
answered on 05 Nov 2016, 03:42 AM

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

0
Accepted
Dimitar
Telerik team
answered on 07 Nov 2016, 10:06 AM
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.
0
Myo
Top achievements
Rank 1
answered on 08 Nov 2016, 09:13 AM

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

0
Dimitar
Telerik team
answered on 08 Nov 2016, 10:00 AM
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.
0
Myo
Top achievements
Rank 1
answered on 08 Nov 2016, 10:19 AM

Hi Dimitar,

It is ok.

Thank you a lot.

Regrads,

Myo

Tags
GridView
Asked by
Myo
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Myo
Top achievements
Rank 1
Share this question
or