patang wrote:
> Question 1
> I have two forms, let say Form1 and Form2. There is datetimepicker
control
> on Form2. In the Load Event of Form2 I have set the default value of
> datetimepicker control to NOW. So as expected when I open the form
the
> default value is set to today's date. Now I sometimes also call Form2
from
> Form1. Ok now here is my problem. Actually when I call Form2 from
within
> Form1 I want to set the set the value of datetimepicker control to
something
> else. I have written following code to call form2 from form1 and
setting the
> value of datetimepicker control:
>
> Dim frm As Form2
> frm = New Form2
> frm.dtbDOB.value = "1 / 1 / 2005"
> frm.showdialog()
>
> I know this is happeneing because when I call form2 from form1, even
though
> I am setting the value of dtbDOB control but it is overwritten by the
value
> set in Load Event.
>
> What should I do ?
One suggestion:
In Form2 declarations:
Private InitialValue As Date = Now
In Form2_Load:
dtp.Value = InitialValue
In Form2:
Public Sub MyShowDialog(ByVal ShowValue As Date)
InitialValue = ShowValue
Me.ShowDialog()
End Sub
Then from elsewhere, if you have f2 As Form2, you can either
f2.ShowDialog() 'to get the default of Now
or
f2.MyShowDialog(SomeOtherDate()) 'to start with some other date
>
> Question 2
> What is the purpose of Text property of DateTimePicker Control ?
>From the help:
The string returned by this property is equivalent to the Value
property with the appropriate formatting or custom formatting applied.
For example, if the Value property is set to 06/01/2001 12:00:00 AM
while the CustomFormat property is set to "dddd, MMMM dd, yyyy", the
Text property value is "Friday, June 01, 2001".
When setting this property, the string must be convertible to an
instance of the DateTime class. It is possible to define a custom
format that results in a string that cannot be converted to a valid
DateTime value. Because of this, the string returned from the Text
property might cause an error if it is passed back to the Text
property. If the string cannot be converted to a date/time value, the
DateTime class throws a FormatException.
>
> Question 3.
> How come I don't see the Text property in the properties window,
however
> when I create an instanace of an form and if that form has
datetimepicker
> control then I can the Text property
>
> frm.dtpDOB.Text
The Text property of the DateTimePicker has its Browsable attribute set
to No. Which might not mean much to you: basically, when you (or in
this case Microsoft) create a control, you can set attributes of the
properties to determine things like, does it appear in the properties
window, what UI it displays in the properties window, what its default
should be, and so on. In this case, since the Text of a DTP is a purely
dervied value, it makes sense to hide it from the Properties window.
>
> Thanks in advance.
--
Larry Lard
Replies to group please
|