GridView exception when adding or cancelling new rows where columns are null

1 Answer 45 Views
GridView
Hayley
Top achievements
Rank 1
Iron
Hayley asked on 10 May 2024, 11:13 AM

Hello,

I have a RadGridView databound to a DataView with AddNewBoundRowBeforeEdit = true. Multiple columns in the DataView.Table have AllowDbNull set to false. I'm getting exceptions however when i try and add a new row without specifying a value for the columns that dont accept Db null, and even if i press Escape to cancel the new row the grid seems to freeze and i can no longer try add new rows. 

I've attached a sample application and a screenshot of the error.  The steps to reproduce the exception in the test app are:

1. Click on any column in add new record row
2. Click on an existing row in the grid. Exception will appear in message box. Press OK
3.. Try and click on add new record row again. Either nothing will happen or another exception will appear.

The exception will also appear if you click in the add new record row, then press Esc key

Thanks,

Hayley

 

1 Answer, 1 is accepted

Sort by
0
Dinko | Tech Support Engineer
Telerik team
answered on 15 May 2024, 06:51 AM

Hello Hayley,

This behavior is a result of disabling the null values inside the bound table. When the new row is initialized with no predefined default values, null values will be applied which will break the logic as null values are not allowed. To avoid this you can subscribe to the DefaultValuesNeeded event. The purpose of this event is to set default values for the new row cells. In the sample project you can use the following code:

this.radGridView1.DefaultValuesNeeded += RadGridView1_DefaultValuesNeeded;

private void RadGridView1_DefaultValuesNeeded(object sender, GridViewRowEventArgs e)
{
    e.Row.Cells[0].Value = "";
    e.Row.Cells[1].Value = "";
    e.Row.Cells[2].Value = 0;
    e.Row.Cells[3].Value = 0;
    e.Row.Cells[4].Value = 0;
}

Regards,
Dinko | Tech Support Engineer
Progress Telerik

A brand new ThemeBuilder course was just added to the Virtual Classroom. The training course was designed to help you get started with ThemeBuilder for styling Telerik and Kendo UI components for your applications. You can check it out at https://learn.telerik.com
Tags
GridView
Asked by
Hayley
Top achievements
Rank 1
Iron
Answers by
Dinko | Tech Support Engineer
Telerik team
Share this question
or