Solved

Timer Control and Datagrid

Posted on 2008-06-19
6
1,023 Views
Last Modified: 2012-06-21
Dear all,

I am trying to develop a software where end user will be informed when a particular time has reached.
For example End user puts a plate into an oven. He then creates an entry into the program with the following details Plate Number (1,2,3,4,..etc), Plate Type(round,oval,...etc), Category(Cold,Hot..etc), Time In(This is a clock time)* and Time Out(When he should take the plate out)*.
*(User does not enter Time In and Out, it automatically calculates the time).

Datagridview then displays the entry on to the form. This entry should turn into yellow when the time is reached (lets say after 5 mins). This will inform the user that its time to take the plate out.

I have reached at the point where an end user can make entries, delete entries. I have even made a timer ticker which displays the time on one of the textboxes meaning "Time In" is displaying a current time and when an end user clicks Add button it adds the time along with other entries into the database.

However, I am not sure how to calculate the Time out (i.e. how to make Time out clock to run always 5mins faster than Time In clock) so when a user makes an entry he is shown Time out as 5mins ahead.

maybe something like
textbox1.text=Now.tolongtimestring.tostring() - Timer1 is set at interval 1000 which runs textbox1 clock
textbox2.text=timer1.interval+5000???

not sure at all on this!

In addition to that I am not sure how to highlight a particular row if it reached the time limit. i.e. turning (lets say Row A) into yellow when 5mins are over and turn Row B into yellow when that time has reached.

I have added a 2nd ticker which colours all the rows. here is the code
        Me.LensesdbDataSet.CLtbl.Clear()
        Me.DataGridView1.Refresh()
        Me.DataGridView1.DataSource = Me.LensesdbDataSet.CLtbl
        Me.CLtblTableAdapter.Fill(Me.LensesdbDataSet.CLtbl)
        Me.DataGridView1.RowsDefaultCellStyle.BackColor = Color.Yellow

howerver I want it to colour only that particular row which has reached its time limit.

I am confuse as to how to achive this, can someone please put me to the right path? Pleaseeeeee

######
Please see attached screenshot to get a better idea
######
Many thanks

Regards

Jehanzeb

Edit:
What if I create another database field with the name of Time Counter and set it to integer. This counter should be able to change its values when the datagrid is refreshes and when it reaches 0 the row should colour yellow!

the big question remains the same though, how would I achieve this programmatically.?
TimerApp.JPG
0
Comment
Question by:jehanzebn
  • 4
  • 2
6 Comments
 

Author Comment

by:jehanzebn
Comment Utility
I think I need to use something along the lines where the datagrid Time Out value keeps changing. i.e. setup datagrid view to refreshes every second and also change value of the column Time out. This way when the Time Out column reaches its limit, it will turn the row into yellow.

But the big question is how do you do it?!!
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
Comment Utility
Try this out...
Public Class Form1
 

    Private ds As New DataSet

    Private tb As DataTable
 

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        tb = ds.Tables.Add("myData")

        tb.Columns.Add("Basket", GetType(String))

        tb.Columns.Add("Lenses", GetType(Integer))

        tb.Columns.Add("Run Type", GetType(String))

        tb.Columns.Add("Time In", GetType(DateTime))

        tb.Columns.Add("Time Out", GetType(DateTime))
 

        DataGridView1.DataSource = tb

        DataGridView1.AllowUserToAddRows = False

        DataGridView1.AllowUserToDeleteRows = False

        DataGridView1.AllowUserToOrderColumns = True

        DataGridView1.AllowUserToResizeColumns = True

        DataGridView1.AllowUserToResizeRows = False

        DataGridView1.Columns("Time In").DefaultCellStyle.Format = "hh:mm:ss"

        DataGridView1.Columns("Time Out").DefaultCellStyle.Format = "hh:mm:ss"

        Timer1.Interval = 500

        Timer1.Enabled = True

    End Sub
 

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim value As Integer

        If Integer.TryParse(TextBox2.Text, value) Then

            Dim dr As DataRow = tb.NewRow()

            dr("Basket") = TextBox1.Text

            dr("Lenses") = value

            dr("Run Type") = ComboBox1.SelectedItem

            dr("Time In") = DateTime.Now

            dr("Time Out") = DateTime.Now.AddMinutes(15)

            tb.Rows.Add(dr)

        End If

    End Sub
 

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

        Timer1.Stop()

        Label1.Text = DateTime.Now.ToString("hh:mm:ss")

        Dim dr As DataGridViewRow

        For i As Integer = 0 To DataGridView1.Rows.Count - 1

            dr = DataGridView1.Rows(i)

            If DateTime.Now > DirectCast(dr.Cells("Time Out").Value, DateTime) Then

                dr.DefaultCellStyle.BackColor = Color.Yellow

            End If

        Next

        Timer1.Start()

    End Sub
 

End Class

Open in new window

0
 

Author Comment

by:jehanzebn
Comment Utility
Morning idle,

you are a super star! this worked like a charm. Though I did approach it bit differently however I was stuck on the point where the gridview was not able to turn into yellow on a specific time (as mentioned in my initial post).

One little question though, when I used your code on a new project whenever I close the application and re run it, it opens the datagrid empty. though I was expecting it to be filled with last entries.
This is important as if a user closes the application by accidently or if electricty goes off then they will loose all their entries hence will forget what time they had to take the lense out of the oven.

Is there any way to show those entries when the application starts again (after a shutdown)? I know how to store them into the database (by using Insert command and using ADO connection).
I have tried the tableadapter.fill option but it didn't work.

many thanks for your superb help!

Regards

J
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 85

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 500 total points
Comment Utility
Whenever you add or remove a record you can save the data like this:

        Dim fs As New System.IO.FileStream("c:\tableData.xml", IO.FileMode.OpenOrCreate)
        tb.WriteXml(fs)
        fs.Close()

When you want to reload the data you can do:

        tb.Clear()
        Dim fs As New System.IO.FileStream("c:\tableData.xml", IO.FileMode.OpenOrCreate)
        tb.ReadXml(fs)
        fs.Close()

I usually only use DataSets/Tables in MEMORY so I don't know much beyond that...  =\
0
 

Author Comment

by:jehanzebn
Comment Utility
Superb! I am using microsoft access as a database which connects via dataset. I like your way too and will def going to use it in another application.

I'll take this as your superc answer!

you have been a lifesaver!

Many thanks

Regards

J
0
 

Author Closing Comment

by:jehanzebn
Comment Utility
Idle_Mind is one of the best guys around, the code is clear and understandable.Superc Job!
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now