I have a grid bound to an ArrayList. My arraylist is a list of business objects with various properties of types integer, decimal and string (never any nulls). During the grid initializelayout, i am adding two custom columns with data types boolean and decimal.
when i add an object to my arraylist and try to set the value of one of the custom columns, i get a 'Data Error', 'Unable to convert from '(null)' to 'System.Decimal''.
How i'm adding the custom fields during initializelayout:
If b.Columns.Exists("selected") = False Then c = b.Columns.Add("selected") c.DataType = GetType(Boolean) c.DefaultCellValue = True c.Nullable = Nullable.Disallow End If If b.Columns.Exists("listamount") = False Then c = b.Columns.Add("listamount") c.DataType = GetType(Decimal) c.DefaultCellValue = 0 c.NullText = "0" c.Nullable = Nullable.Disallow End If
How I'm adding a new object to my arraylist:
Private Sub AddOptionToSelected(ByVal optionid As Integer) Dim oi As New DealOptionItem oi.LoadBase(optionid) Dim i As Integer = Me.LIST.Add(oi) Me.grdOptions.DataBind() Dim row As UltraGridRow = Me.grdOptions.Rows.GetRowWithListIndex(i) row.Cells("selected").Value = True ' <---- this line shows the data error row.Cells("listamount").Value = oi.SALEAMOUNT End Sub
korazy said:It's not an exception. It's just a message box from the grid that displays the error 'Unable to convert from '(null)' to 'System.Decimal'', with the title 'Data Error'. No expection is thrown and the msgbox does not come from my code.
If it's displaying as a MessageBox and not an exception, then it must be an exception coming from your data source which the grid is handling and raising to you as an event (probably the CellDataError event).
Try setting the IDE to break on all run-time exceptions and you should be able to catch the real exception coming from your data source.
It's not an exception. It's just a message box from the grid that displays the error 'Unable to convert from '(null)' to 'System.Decimal'', with the title 'Data Error'. No expection is thrown and the msgbox does not come from my code.
I found the my custom column 'listamount' was null after adding the row. and for some reason if I revesred the order of settings my values the prompt stopped. When i create my custom columns, I am setting a default value and setting 'nullable' to disallow. but those are not working. when adding a row, they custom columns values are null and not their default value.
By changing this:
row.Cells("selected").Value = True ' <---- this line shows the data error row.Cells("listamount").Value = oi.SALEAMOUNT
To this:
row.Cells("listamount").Value = oi.SALEAMOUNT
row.Cells("selected").Value = True
Hi,
There's not much information here to go on. What version of the grid are you using?
What does the call stack of the exception look like?
It seems clear that your data source is unable to support null values, since you are using value types that are not nullable.
There's no reason why the grid should be displaying an error about nulls if you are not actually using any.