Question Smallest Value in DataGridView Column

BleepyEvans

Active member
Joined
May 2, 2011
Messages
41
Programming Experience
1-3
Hi guys, ive been working on a stopwatch project as some of you know.

Ive created the stopwatch, and thanks to some of your members, I finally got the stopwatch to add the timings into a datagridview every time the lap button is pressed.

Although because im converting the times to strings im having trouble trying to get the smallest value for the fastest lap.

Here what some of my form looks like:
Untitled-1.png

And some of my code:
Private Sub LapButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LapButton.Click
        i += 1
        If DataGridView1.Rows.Count > 0 Then
            DataGridView1.Rows.Add(i, StopwatchLabel.Text, laptimerer.Text)
        Else
            DataGridView1.Rows.Add(i, StopwatchLabel.Text, StopwatchLabel.Text)
        End If
        Label3.Text = Label3.Text + Val(1)
        lapTime = DateTime.Now
    End Sub


    Private Sub StartButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StartButton.Click
        startTime = DateTime.Now
        StartStopWatch()
    End Sub


 Public Sub StartStopWatch()
        startTime = DateTime.Now
        StopWatch.Start()
        InRaceCountDownTime = DateTime.Now.AddMinutes(racelength.Text)
        InRaceCountDownTimer.Start()
        ProgressBar1.Value = 0
        lapTime = DateTime.Now
        Lap.Start()
    End Sub


 Private Sub Lap_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Lap.Tick
        Dim span As TimeSpan = DateTime.Now.Subtract(lapTime)
        laptimerer.Text = span.Minutes.ToString & ":" & span.Seconds.ToString & "." & span.Milliseconds
      End Sub


Any ideas guys?
 
The cast would work if the Value of that cell was a TimeSpan, so obviously the Value of that cell is not a TimeSpan. Have you checked what the Value of that cell is? That would likely give you a clue as to what you're doing wrong.
 
Yep, The code you gave before found the best value from column 0 which is the first column. I added a column before the one you created in your demo. Lap Number which is an interger.

So I just changed your code to
VB.NET:
 Select DirectCast(row.Cells("lapTimeColumn").Value, TimeSpan)).Min()
 
Back
Top