[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Timer Control and Datagrid

Posted on 2008-06-19
6
Medium Priority
?
1,101 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 86

Accepted Solution

by:
Mike Tomlinson earned 2000 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 86

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

650 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