Hey guyz! i was testing a code supplied at the MSDN
http://msdn.microsoft.com/library/de...classtopic.asp on using DataGridColumnStyle to add form cotrols to a datagrid (the MSDN its a DateTimePicker).
However, everytime i run the code it displays the data correct but when i click on the last row i.e the add New row, the code breaks at the after Protected Overloads Overrides Sub Edit( _
ByVal [source] As CurrencyManager, _
ByVal rowNum As Integer, _
ByVal bounds As Rectangle, _
ByVal [readOnly] As Boolean, _
ByVal instantText As String, _
ByVal cellIsVisible As Boolean) function and displays the error msg Cast from type 'DBNull' to type 'String' is not valid. i know the reason why this is so, which is because... their is no datavalue at the [source] variable.
I have tried countless if statement IsDBNull() functions IIf() functions but everytime the code still breaks either inside the function or back at the application.Run(Form1).
If you can help please come to my rescue..coz its stressing me out. I hope its some kind of bug en not my programming skills.
The full function is below:
Protected Overloads Overrides Sub Edit( _
ByVal [source] As CurrencyManager, _
ByVal rowNum As Integer, _
ByVal bounds As Rectangle, _
ByVal [readOnly] As Boolean, _
ByVal instantText As String, _
ByVal cellIsVisible As Boolean)
MyBase.Edit(source, rowNum, bounds, [readOnly], instantText, cellIsVisible)
Dim value As DateTime = _
CType(GetColumnValueAtRow([source], rowNum), DateTime)
If cellIsVisible Then timePicker.Bounds = New Rectangle _
(bounds.X, bounds.Y, bounds.Width, _
bounds.Height)
timePicker.Value = value
timePicker.Visible = True
AddHandler timePicker.ValueChanged, _
AddressOf TimePickerValueChanged
Else
timePicker.Value = value
timePicker.Visible = False
End If
If timePicker.Visible Then DataGridTableStyle.DataGrid.Invalidate(bounds)
End If
End Sub
LION OF JUDDAH!