Solved

Timer Control and Datagrid

Posted on 2008-06-19
6
1,043 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
ID: 21821814
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
ID: 21825853
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
ID: 21829549
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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 85

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 500 total points
ID: 21831647
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
ID: 21832744
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
ID: 31468784
Idle_Mind is one of the best guys around, the code is clear and understandable.Superc Job!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

821 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