Hi All
I have created a ToolStripDateTimePicker with the following code:
Public Class ToolStripDateTimePicker
Inherits ToolStripControlHost
Public Event ValueChanged(ByVal sender As Object, ByVal e As
EventArgs)
Sub New()
MyBase.new(New DateTimePicker)
AddHandler Me.DateTimePicker.ValueChanged, AddressOf
ValueChanged_Handler
End Sub
Private Sub ValueChanged_Handler(ByVal sender As Object, ByVal e As
EventArgs)
RaiseEvent ValueChanged(sender, e)
End Sub
Public ReadOnly Property DateTimePicker() As DateTimePicker
Get
Return DirectCast(MyBase.Control, DateTimePicker)
End Get
End Property
Public Property Value() As Date
Get
Return DirectCast(MyBase.Control, DateTimePicker).Value
End Get
Set(ByVal value As Date)
DirectCast(MyBase.Control, DateTimePicker).Value = value
End Set
End Property
End Class
This all works fine except I am unable to use the ApplicationSettings
feature of Visual Studio 2005/.Net 2.0.
I have created a form, and added a ToolStrip to it. I then added my
ToolStripDateTimePicker to it (had to do this by adding a
ToolStripTextbox and then changing its type as it wasnt available from
the list).
I then click on the ToolStripDateTimePicker and Select
Data->(Application Settings)->(PropertyBinding). I then add the
binding to the Value property of the object.
However, when I change the value of the of the ToolStripDateTimePicker
it doesnt update the setting and subsequently doesnt save it when the
program exits. However if I update the setting, the
ToolStripDateTimePicker DOES update. This makes me believe that
wrapping the DTP in the toolbar means I am missing an important event
that triggers the change of the setting when the value of the DTP
changes.
I know I can manually set the value of the setting to be the value of
the DTP which does work, but I'd rather find the proper solution.
Thanks in advance
Kevin
Kevin - 23 Jan 2007 11:13 GMT
Actually, changing the setting doesnt seem to update the DTP, sorry!
Kevin - 26 Jan 2007 13:58 GMT
Have done some more digging, I think I need to implement
IBindableComponent, but I havent done this yet so cant confirm it.
see "Application Settings for Windows Forms" in msdn help for details.
Kevin - 26 Jan 2007 15:15 GMT
I can confirm this is correct. You should also implement
System.ComponentModel.INotifyPropertyChanged
and raise the event when the property you are binding on changes.