Mik Mak
asked on
Detect active field before Button click
I'm working on a VB Compact Framework application, and have a Date-picker field containing (surprise:) dates.
We have six of theses date fields (EventDate1, EventDate2...EventDate6). Sometimes the user needs to put in a special date (like "31-12-2099") which is a code for a special event. So I've made a button to register this date "code" - but I don't know how to detect which of the EventDateX fields was activated right before the user pressed the special date button ?
Please advice
MIchael
We have six of theses date fields (EventDate1, EventDate2...EventDate6). Sometimes the user needs to put in a special date (like "31-12-2099") which is a code for a special event. So I've made a button to register this date "code" - but I don't know how to detect which of the EventDateX fields was activated right before the user pressed the special date button ?
Please advice
MIchael
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You could do the exact same thing but with the GotFocus() event instead.
ASKER
Excellent - I'll test it later and report back :)
ASKER
Sorry for being slow, but how do I assign the value to the datepicker field in this - I'm unsure how I should use the LastEventDate to reference the field ?
Private Sub btnSpecialDate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSpecialDate.Click
If Not IsNothing(LastEventDate) Then
' ... use "LastEventDate" in here...
End If
End Sub
Private Sub btnSpecialDate_Click(ByVal
If Not IsNothing(LastEventDate) Then
' ... use "LastEventDate" in here...
End If
End Sub
"LastEventDate" will be an actual reference to the last used DateTimePicker.
You can just use its Value() property:
You can just use its Value() property:
Private Sub btnSpecialDate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSpecialDate.Click
If Not IsNothing(LastEventDate) Then
MessageBox.Show("Last Event Date Selected: " & LastEventDate.Value.ToString())
End If
End Sub
ASKER
So I should be able to use something like this ?
Private Sub btnSpecialDate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSpecialDate.Click
If Not IsNothing(LastEventDate) Then
LastEventDate.Value = "31-12-2099"
LastEventDate = Nothing ' to reset the field reference ?
End If
End Sub
Private Sub btnSpecialDate_Click(ByVal
If Not IsNothing(LastEventDate) Then
LastEventDate.Value = "31-12-2099"
LastEventDate = Nothing ' to reset the field reference ?
End If
End Sub
Pass it an actual DateTime like this:
LastEventDate.Value = New DateTime(2099, 12, 31)
*Though I'm not sure the year 2099 is valid! Is that a typo?
Setting it to Nothing is valid as well.
LastEventDate.Value = New DateTime(2099, 12, 31)
*Though I'm not sure the year 2099 is valid! Is that a typo?
Setting it to Nothing is valid as well.
ASKER
2099 is not a type :) It works like a charm - thank you for your speedy help :)
ASKER
The user should just need to click/mark the field, and then hit the special date button