Windows Phone DatePicker doesn't update its Value - vb.net

I make a windows phone 7.8 app and i'm using a datepicker.
When i load the page that contains the datepicker, i pass the date and is displayed correctly.My code is:
Protected Overrides Sub OnNavigatedTo(ByVal e As System.Windows.Navigation.NavigationEventArgs)
Dim mydate As String = Nothing
If NavigationContext.QueryString.TryGetValue("date", mydate) Then
eventdate = Date.Parse(mydate)
datePicker.Value = eventdate
EndIf
End Sub
But when i try to change the date , the datepicker doesn't hold the new date. Does anybody know why?

Your problem is due to the way you're not correctly managing the page lifecycle.
When you go to the date selector this is actually a separate page. When tapping the "tick" to confirm the new data selection you'll return to your page. Based on your code above, at this point you'll load the date from the NavigationContext again and so the selected date is lost.
The solution is to query the NavigationEventArgs and only read the query string when the NavigationMode is New.

Related

VB.NET - Date Time Picker saves current date by default, even if no date is chosen

I have a date picker named 'paidDateDp' in my form. My configuration is as below
Property Setting:
Format="Custom"
Private Sub paidDateDp_ValueChanged(sender As Object, e As EventArgs) Handles paidDateDp.ValueChanged
paidDateDp.CustomFormat = "dd-MMM-yyyy"
End Sub
While executing, I see the paidDateDp value is blank. Even if I dint choose any value, when I attempt to save the details of the form to MSAccess using my Oledbadapter query, by default, the current date is getting saved against the paidDate column of my access table.
How to save empty date to my access table from my datetime picker, provided no date is selected?
Someone please suggest me.

Passing and Viewing Combobox Text in VB

I have a program with two forms: Form1 and FocusPRG. On the FocusPRG form I have two comboboxes set to List, one that let's you pick a Start Time and one that let's you pick a Stop Time for a process. Right now all I want to do is have Form1 look at the selected times and write them to a log file but the log file just shows blank lines and not any of the actual text. Here is the code on Form1 I am using:
Dim StartTime As String
Dim StopTime As String
StartTime = FocusPRG.StartTimePicker.SelectedText
StopTime = FocusPRG.StopTimePicker.SelectedText
WriteLog(StartTime)
WriteLog(StopTime)
What am I missing?
The SelectedText property does not do what you think it does. It's not the text of the selected value. Just like in a TextBox, it's the text that the user has highlighted using either the mouse or keyboard. If you want the text displayed in the control then you want the Text property, again, just like a TextBox.
Use this:
Dim StartTime As String
Dim StopTime As String
StartTime = FocusPRG.StartTimePicker.SelectedItem.ToString()
StopTime = FocusPRG.StopTimePicker.SelectedItem.ToString()
WriteLog(StartTime)
WriteLog(StopTime)
That is to say, use the SelectedItem property of the ComboBox instead of the SelectedText property.
If you read the documentation of the two at MSDN, you can easily see the difference:
Definition of SelectedText says:
Gets or sets the text that is selected in the editable portion of a ComboBox.
Definition of SelectedItem says:
Gets or sets currently selected item in the ComboBox.
FocusPRG must be an instance of the form, not just a class name. When creating FocusPRG, do something like:
dim FocusPRG1 as new FocusPRG
FocusPRG1.Show()
Also use Text, not SelectedText to get the user's input.
StartTime = FocusPRG1.StartTimePicker.Text
StopTime = FocusPRG1.StopTimePicker.Text
Also, the question is a little confusing because you say the controls are combo boxes but they are call xxxTimePicker, which suggests a different type of control.

All elements of an array cannot be accessed from a for loop in monthCalendar Control - Visual Basic

I have a bit of an issue here with the monthCalendar Control in Visual Basic. What is happening in the program is I have a calendar and a text box. The user selects a date on the calendar, then types in information into the textbox component, then presses the add button. From there the add button sets up a parallel array that contains the selected date and the added string from the text box as a way to add planner information for each date. Then the date is bolded for each time an addition like this has happened.
From there you are suppose to be able to click each bolded date and view the information you added. The issue is this only works on the last added date. For some reason it will only read the last element added to the array. I have the for loop down below. I do not understand why I cannot select any bolded date and view the text added. I have option strict on so I know no data loss is occurring. Also I know the date is being selected and placed into the string each time a date is selected on the calendar because I am displaying it onto a label each time. What is the problem. Is it some logical error I am not catching or is it something else?
Public Sub MonthCalendar1_DateChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MonthCalendar1.DateChanged
For index As Integer = 0 To intSizeOfSelectedDatesAry - 1
strSelectedDay = CStr(MonthCalendar1.SelectionRange.Start) ' place the selected date into a string
lblError.Text = strSelectedDay
lblError.Visible = True
Dim strAryDate As String = arySelectedDates(index)
If (arySelectedDates(index) = strSelectedDay) Then
lblInstructions.Text = strSelectedDay
lblSelectedDate.Text = aryTextForDates(index)
index = intSizeOfSelectedDatesAry - 1
End If
Next
End Sub

How to replace label with dates

I am using Visual Basic 2010. My question can best explained by these images.
I would like to know how to make the labels appear as dates depending on what the DateTimePicker is set on. For Example:
This is what the code looks now that I have solved my issue.
Private Sub MonthCalendar1_DateChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DateRangeEventArgs) Handles MonthCalendar1.DateChanged
Me.Label14.Text = CStr(Me.MonthCalendar1.SelectionRange.Start)
Me.Label13.Text = CStr(Me.MonthCalendar1.SelectionRange.Start.AddDays(6))
Me.Label12.Text = CStr(Me.MonthCalendar1.SelectionRange.Start.AddDays(1))
Me.Label11.Text = CStr(Me.MonthCalendar1.SelectionRange.Start.AddDays(2))
Me.Label10.Text = CStr(Me.MonthCalendar1.SelectionRange.Start.AddDays(3))
Me.Label9.Text = CStr(Me.MonthCalendar1.SelectionRange.Start.AddDays(4))
Me.Label15.Text = CStr(Me.MonthCalendar1.SelectionRange.Start.AddDays(5))
End Sub
I don't have Visual Studio installed on this computer, so I can't give you the exact code, so I will try to explain it.
In the code of the event for the DateTimePicker, you have to calculate for each label the difference in days of the week from your date to the date you want to show (Wednesday to Saturday - 3 days (and you have a little error in the images - you have to switch Wednesday with Tuesday), Thursday to Saturday - 2 days, and so on...).
After that, you subtract (or add, if the day is after the chosen date) the referential date with the corresponding value from above, and you get the date needed. Now you only have to show the result in the label.
Found the answer to my own question.
To retrieve a date and display it in a label:
In the File menu, click New Project.
The New Project dialog box appears.
Click Windows Forms Application and then click OK.
Add a Label control to the form, leaving the default name Label1.
Remove the text from the Text property of the Label control.
Add a MonthCalendar control to the form, leaving the default name MonthCalendar1.
Double-click the MonthCalendar control to enter the default event handler in the Code Editor.
In the MonthCalendar1_DateChanged event handler, add the following code to add items to the list:
Me.Label1.Text = CStr(Me.MonthCalendar1.SelectionRange.Start)
Return to Designer view and add a DateTimePicker control to the form, leaving the default name DateTimePicker1.
Double-click the DateTimePicker control to enter the default event handler in the Code Editor.
In the DateTimePicker_ValueChanged event handler, add the following code to add items to the list:
Me.Label1.Text = CStr(Me.DateTimePicker1.Value)
Press F5 to run the program.
When the form appears, click a date in the MonthCalendar control and verify that the date is displayed in the label.
Click the drop-down arrow of the DateTimePicker control and select a date.
The date and time are displayed in the label.

Referencing UserControl's constituent TextBox from another form at design time vb.net

Right up front, I'm writing in vb code, not c#.
I've checked out the suggested forum subjects and none apply,(that I could find) so here it is. I'm relatively new to vb.net. (come from vb6)
I'm creating a user control_1 which contains textboxes and a button. Control_1 inherits from another user control_2 (a few textboxes and the calendar form button). When I press the button it launches a Calendar form containing a CalendarControl.
Works fine so far.
Now I need to return the CalendarControl value on it's Calendar form back to the unseated user control_1. I am talking design time here, User Control_1 is not seated on a form yet.
I do not want to trigger the calendar form from it seated form because I want this proccess to be encapsulated.
I wrote the code as a forms based app to make sure my logic and app worked. Now I'm trying to move the code and constituent controls into a control library.
I've tried calling Usercontrol_1 from my calendar form but it does not show any of my shared controls or properties. I've tried Me.Parent.Controls in a For Each loop. It found the controls but said I needed to use the New keyword. I tried new and it didn't work. Maybe I misunderstood what the intellisence was talking about.
Thanks in advance for your time and help.
At design time you cannot click a button which opens another form. Therefore I am really not sure what you are trying to achieve at design time.
I don't know the calender control you are using. Therefore I going to explain a possible solution using a DateTimePicker. On the calender form (let's call it fdlgCalender add a property that allows accessing the selected date of the calender control publicly:
Public Property SelectedDate() As Date
Get
Return DateTimePicker1.Value
End Get
Set(ByVal value As Date)
DateTimePicker1.Value = value
End Set
End Property
On your UserControl containing the calender button, create a similar property. This time we are using a nullable date in order to indicate the situation where no date has been selected
Public Property SelectedDate As Date?
Now you can call the calender form like this:
Dim fdlg As New fdlgCalender()
If SelectedDate.HasValue Then
fdlg.SelectedDate = SelectedDate.Value
Else
fdlg.SelectedDate = Today
End If
' Assuming that the dialog form sets the `DialogResult` correctly
If fdlg.ShowDialog() = DialogResult.OK Then
SelectedDate = fdlg.SelectedDate
Else
SelectedDate = Nothing
End If
Now you can access the date from outside of your user control through the SelectedDate property.
(The code is not tested)