|
-
May 29th, 2004, 06:58 AM
#1
Thread Starter
New Member
Object Reference not set to instance of object
I have the following code (which I have used before with no prob) and continue to get an error that is baffling me. I'm doing a databind to a lable and passing the value to a format routine so I can control output on things like dates. Error is ...
An unhandled exception of type 'System.NullReferenceException' occurred in .....
Additional information: Object reference not set to an instance of an object.
CODE:
With m_objData
RMADataGrid.DataSource = .RMA
Dim objBinding As Binding
m_cmrRMA = _
CType(BindingContext(.RMA), _
CurrencyManager)
lblRMADate.DataBindings.Add(New _
Binding("Text", .RMA, "RMA Date"))
AddHandler objBinding.Format, _ <<< Chokes here
AddressOf FormatLabelAsDateString
........................................
Private Sub FormatLabelAsDateString(ByVal sender As Object, _
ByVal cevent As ConvertEventArgs)
If cevent.DesiredType Is GetType(String) Then
If cevent.Value Is DBNull.Value Then
cevent.Value = ""
Else
cevent.Value = Convert.ToDateTime(cevent.Value).ToString("d")
End If
End If
End Sub
Any suggestions would be most appreciated. Thanks!
-
May 29th, 2004, 08:39 AM
#2
Hyperactive Member
ok different coding approach but it might help and it does work consistently:
Dim b1 As Binding = New Binding("text", ds2, "Tenancies.StartDate")
AddHandler b1.Parse, AddressOf StrDat
AddHandler b1.Format, AddressOf DatStr
DteTxtBox1.DataBindings.Add(b1)
Note: DteTxtBox1 is a custom class inherited from textbox, but all it does, is only allow valid values to be entered.
Private Sub DatStr(ByVal sender As Object, ByVal cevent As ConvertEventArgs)
If Not cevent.DesiredType Is GetType(String) Then
Exit Sub
End If
Try
cevent.Value = CType(cevent.Value, Date).ToString("dd/MM/yyyy")
Catch
' null value trap
End Try
End Sub
Private Sub StrDat(ByVal sender As Object, ByVal cevent As ConvertEventArgs)
If Not cevent.DesiredType Is GetType(Date) Then
Exit Sub
End If
cevent.Value = Date.Parse(cevent.Value)
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|