DataBinding Format Question

  • Thread starter Thread starter Katty
  • Start date Start date
K

Katty

I am using the following code to apply the databinding format for Date
(04/12/2003)

**********************CODE*****************************
Private WithEvents DateBinding As Binding

DateBinding = New Binding("Text", Me.DsReport1, _
"Report.Date")
Me.RichTextBox.DataBindings.Add(DateBinding)

Sub Format(ByVal sender As Object, ByVal e As ConvertEventArgs) Handles _
DateBinding.Format
Dim dt As DateTime = CType(e.Value, DateTime)
e.Value = dt.ToString("dd/MM/yyyy")
End Sub

*********************************************************
It works perfectly but every time I load the form on design mode, the
following messages appear:

"The variable DateBinding is not declared or it was not assigned never"
"The type System.Windows.Forms.Form does not have a field named DateBinding"

Now, this can't be right and I sure don't want to leave it like that but I
can't figure it out.
Any recommendations please?

Thanks!
 
Hi Miha,

I see what you're thinking, my code is located in the Windows Form Designer
Code Generated Section,
just after the assignation of the RichTextBox properties values, is it a
mistake to put it there? Can't I do this?
 
Right, I've moved the code to the Form Load event, and the messages stopped.
Now, is this the best way to do it?

Thanks a lot!
 
I normally put the code that shouldn't execute at design time in override of
OnLoad method.
There I check for !DesignMode (not DesignMode in VB)
 
Back
Top