Problems with vb express date picker control

I have 2 date picker controls on a form.

If i pick a date in the current month, no problems.

If i try to hit the left or right arrows using the mouse click to continue searching its very unstable and usally just moves the 1st day of the previous month.

Any ideas most welcome....
SweetingAAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Fernando SotoRetiredCommented:
Hi SweetingA;

To your statement, "If i try to hit the left or right arrows using the mouse click to continue searching its very unstable and usally just moves the 1st day of the previous month."; What do you mean byits very unstable?

If I remember correctly if you click on the previous month button it will move to the previous month highlighting the first of the month and the same is true if you click on next month button.
0
SweetingAAuthor Commented:
Hi Fernando,

Most of teh time it does not leave the calendar open, it just puts the first day of the last month in and closes the calendar.  I have to do it several times to try and get a chosen date in an earlier month.

Regards
0
Fernando SotoRetiredCommented:
Hi SweetingA;

Clicking on a date will close the calendar but clicking the left and right arrows should move the calendar to the next/previous month without closing unless you click outside of the calendar. So to choose a date in a earlier month click on the left arrow multiple times until you get to the month you want and then click on the date in that month, clicking on the date will close the calendar. Another way to do that would be to open the calendar click between the month name and one of the left/right arrows which will display all 12 months name click on the month you want to go to and it will display that month and then select you date. The calendar should not close while you do one of the above ways.
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

SweetingAAuthor Commented:
I can navigate round clicking the centre date to change months and years, that way works fine but when i click the rarows its a bit flakey and most of the time picks the first day in the month and closes the calendar view.

Its not the end of the world but it is very annoying, i just though it may be a bug taht someone might know how to work around.

Thanks anyway.
0
Fernando SotoRetiredCommented:
I am unable to reproduce that issue. If you can build a test app where this is happening I will have a look at it. If you do create the test app please zip the complete project with all files and post to the web where I can download it a web site such as Microsoft OneDrive.
0
SweetingAAuthor Commented:
OK Fernando thanks, i'll take a look but it might take me an hour or so as the wife is giving me earache for being on the PC all the time.

Thanks
0
SweetingAAuthor Commented:
Hello Fernando,

Link is below

https://onedrive.live.com/redir?resid=C91A0203A9EBBE32!111&authkey=!AI7fOb9YbxYNZcc&ithint=file%2czip

As i said sometimes it works sometimes not but you will see what i mean very quickly.

Select "User Defined" in the combo box then use the date pickers.

Thanks Alan
0
Fernando SotoRetiredCommented:
Hi SweetingA;

A couple of issues.

1.  You have the following two lines of code in a couple of places. This is configuration of the DateTimePicker control and should only be done once like in the form load event. Leaving it set in this way will cause the text box of the control to NOT display anything even when the date has been set.

datStart.CustomFormat = " "
datStart.Format = DateTimePickerFormat.Custom

2.  When wireing up controls you need to be careful because they may fire multiple times. An example of this is the datStart_ValueChanged event. This event will fire on all clicks within the opened calendar window, for example left/right arrows, white space between month name and an arrow and the date itself. So whatever code is placed in it will be executed multiple time.

3.  The issue causing the control to be unstable is that you had configuration commands in the datStart_ValueChanged and this is causing the control to reset the calendar drop down. Some events that can be used that execute once is Enter, Leave, Validating, Validated and some others.

To see it work like it should, do the following two things, 1 in the DTGraph_Load event give a format value to datStart.CustomFormat and 2 comment out the line in datStart_ValueChanged event.
0
SweetingAAuthor Commented:
Hello Fernando,

As ususal you are spot on.  However thsi only solves the problem at date start and not date end.  I need to do some manipulation after date end and it seems any code in the ValueChanged event destabilies the date picker.  Any further ideas?  Revised code it below - i have emade some changes to the datEnd and deleted the datStart.

What i initially wanted to do is execute the SQL as long as there were dates in the 2 date boxes and anytime either of the boxes were updated.

Any further ideas?


    Private Sub datEnd_ValueChanged(sender As System.Object, e As System.EventArgs) Handles datEnd.ValueChanged
        'Date Range OEE
        Try
            datEnd.Format = DateTimePickerFormat.Long
            Dim sd As DateTime = datStart.Value.ToString("yyyy/MM/dd")
            Dim ed As DateTime = datEnd.Value.ToString("yyyy/MM/dd")
            Dim Result As DialogResult
            Result = MsgBox("Are you sure the dates are correct?", vbQuestion + vbYesNo, "Message Alert")
            If Result = System.Windows.Forms.DialogResult.Yes Then
                Dim mind As DateTime
                Dim maxd As DateTime
                SQL.RunQuery("SELECT Max(Date) As MaxDate, Min(Date) As MinDate  FROM qry_OEE_DateRange")
                For Each i As Object In SQL.SQLDataSet.Tables(0).Rows
                    maxd = i.Item("MaxDate")
                    mind = i.Item("MinDate")
                Next
                Dim pmind As DateTime
                Dim pmaxd As DateTime
                pmind = sd
                pmaxd = ed
                If ed > maxd Then pmaxd = maxd
                If sd < mind Then pmind = mind
                SQL.RunQuery("SELECT OEE As OEE, Date As Date FROM qry_OEE_DateRange WHERE Date >= '" & pmind.ToString("yyyy/MM/dd") & "' And Date <= '" & pmaxd.ToString("yyyy/MM/dd") & "' ")
                If SQL.recordcount = 0 Then
                    MsgBox("No records available for this selection, please reselect", vbExclamation + vbOKOnly, "Message Alert")
                    Chart1.Series(0).Points.Clear()
                    Exit Sub
                End If
                SQL.SQLDA.Fill(SQL.SQLDataSet, "qry_OEE_DateRange")
                Chart1.DataSource = SQL.SQLDataSet.Tables("qry_OEE_DateRange")
                Dim Series1 As Series = Chart1.Series(0)
                Series1.Name = "Date Range OEE"
                Chart1.Series(Series1.Name).XValueMember = "Date"
                Chart1.Series(Series1.Name).YValueMembers = "OEE"
                Chart1.Series(0).CustomProperties = "DrawingStyle = Cylinder ,PixelPointWidth = 15"
                Chart1.ChartAreas(0).AxisX.Title = "Date"
                Chart1.ChartAreas(0).AxisY.Title = "% OEE"
                'Chart1.ChartAreas(0).AxisX.Maximum =
                'Chart1.ChartAreas(0).AxisX.Minimum =
                Chart1.ChartAreas(0).AxisY.Minimum = 0
                Chart1.ChartAreas(0).AxisY.Maximum = 120
                'Chart1.ChartAreas(0).AxisX.Interval =
                Chart1.ChartAreas(0).AxisY.Interval = 20
                Chart1.ChartAreas(0).AxisX.TitleFont = New Font("Arial", 10, FontStyle.Bold)
                Chart1.ChartAreas(0).AxisY.TitleFont = New Font("Arial", 10, FontStyle.Bold)
                Chart1.ChartAreas(0).AxisX.LabelStyle.Font = New Font("Arial", 6)
                Chart1.ChartAreas(0).AxisY.LabelStyle.Font = New Font("Arial", 6)
                Chart1.ChartAreas(0).AxisX.MajorGrid.LineDashStyle = DataVisualization.Charting.ChartDashStyle.Dash
                Chart1.ChartAreas(0).AxisY.MajorGrid.LineDashStyle = DataVisualization.Charting.ChartDashStyle.Dash
                Chart1.ChartAreas(0).AxisX.LabelStyle.Angle = 0
                Chart1.Series(0).XValueType = ChartValueType.DateTime
                Exit Sub
            Else
                MsgBox("Please make another selection", vbExclamation + vbOKOnly, "Message")
                datStart.Visible = False
                datEnd.Visible = False
                labDateFilter.Visible = False
                labTo.Visible = False
                SQL.SQLDataSet.Clear()
                Chart1.Series(0).Points.Clear()
                cboPeriodSelector.SelectedIndex = -1
                cboPeriodSelector.Focus()
                Exit Sub
            End If
        Catch ex As SqlException
            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub

Thanks for the help so far.
0
Fernando SotoRetiredCommented:
Hi SweetingA;

I have looked at your new code. My first suggestion would be to move the code in datEnd_ValueChanged to the datEnd_Leave event handler. The reason for this as I stated in my last post is that the ValueChanged event handler is called multiple times and will cause multiple calls to the SQL server and sometimes with invalid date range values. Doing it in the Leave event will give better results seeming it gets called once. The only thing with this is that the Leave event gets called once the user moves focus away from the datEnd control.

Another thing I would suggest to you doing is moving the line of code at the top of the handler, datEnd.Format = DateTimePickerFormat.Long, to the datEnd_Enter. This way it is set up long before the user starts to modify the value of the DateTimePicker.
0
SweetingAAuthor Commented:
Hi Fernando,

I can't find any LeaveEvent handler?
0
Fernando SotoRetiredCommented:
Hi SweetingA;

I had the same issue looking for it through the Properties window and I do not know why. You will be able to use this way of getting it. Open the code file for the form. Directly above the code window you will find two combo boxes, the one on the left has all the controls on that form, select the datEnd control. The combo box on the right has all the events select the Leave event from that list. One you have selected it, it will place the event in code. If all else fails this is the signature of the event, cut and paste into your code.

Private Sub datEnd_Leave(sender As Object, e As EventArgs) Handles datEnd.Leave

End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SweetingAAuthor Commented:
Hi Fernando,

I tried it and the date picker works better in the datEnd but is still not perfect, problem is that the graph does not refresh as i don't really leave the combobox - thats why the valuechanged was a better option
0
SweetingAAuthor Commented:
Hi Fernando,

I found this code which works a treat.....

Private Sub DateTimePicker1_ValueChanged(ByVal sender As Object, ByVal e As EventArgs) Handles DateTimePicker1.ValueChanged
  Me.Text = DateTimePicker1.Value.ToString
End Sub

Private Sub DateTimePicker1_DropDown(ByVal sender As Object, ByVal e As EventArgs) Handles DateTimePicker1.DropDown
  RemoveHandler DateTimePicker1.ValueChanged, AddressOf DateTimePicker1_ValueChanged
End Sub

Private Sub DateTimePicker1_CloseUp(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker1.CloseUp
  AddHandler DateTimePicker1.ValueChanged, AddressOf DateTimePicker1_ValueChanged
  Call DateTimePicker1_ValueChanged(sender, EventArgs.Empty)
End Sub

Regards
Alan
0
SweetingAAuthor Commented:
I've requested that this question be closed as follows:

Accepted answer: 0 points for SweetingA's comment #a40239605

for the following reason:

The solution is signifcantly better than my original code and gave me a good understanding of the restrictions surrounding the use of the date picker.
0
SweetingAAuthor Commented:
The solution is signifcantly better than my original code and gave me a good understanding of the restrictions surrounding the use of the date picker.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.