D
Derek Chong
Hi all,
How do I stop the grid control from trying to save a new row to the
datatable rows collection when I change the selected cell on the new row.
It is only a problem with mandatory columns. After adding a new row,
clicking on the Date_Recorded cell of the new row raises the following error
An unhandled exception of type 'System.Data.NoNullAllowedException' occurred
in System.Data.dll
Additional information: Column 'Id' does not allow nulls.
Here is a code snippet that will cause the problem
Dim dtInventory As DataTable
Private Sub frmTest_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
dtInventory = New DataTable
'Define inventory table
dtInventory.Columns.Add("Id", GetType(Integer))
dtInventory.Columns!Id.AllowDBNull = False
dtInventory.Columns.Add("Date_Recorded", GetType(Date))
dtInventory.Columns!Date_Recorded.DefaultValue = Now
dtInventory.Columns!Date_Recorded.AllowDBNull = False
grdData.DataSource = dtInventory
End Sub
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnAdd.Click
Me.BindingContext(dtInventory).AddNew()
End Sub
Pocket PC 2003
CF SR1
How do I stop the grid control from trying to save a new row to the
datatable rows collection when I change the selected cell on the new row.
It is only a problem with mandatory columns. After adding a new row,
clicking on the Date_Recorded cell of the new row raises the following error
An unhandled exception of type 'System.Data.NoNullAllowedException' occurred
in System.Data.dll
Additional information: Column 'Id' does not allow nulls.
Here is a code snippet that will cause the problem
Dim dtInventory As DataTable
Private Sub frmTest_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
dtInventory = New DataTable
'Define inventory table
dtInventory.Columns.Add("Id", GetType(Integer))
dtInventory.Columns!Id.AllowDBNull = False
dtInventory.Columns.Add("Date_Recorded", GetType(Date))
dtInventory.Columns!Date_Recorded.DefaultValue = Now
dtInventory.Columns!Date_Recorded.AllowDBNull = False
grdData.DataSource = dtInventory
End Sub
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnAdd.Click
Me.BindingContext(dtInventory).AddNew()
End Sub
Pocket PC 2003
CF SR1