Sabtu, 02 April 2016

VB.NET - How To Get The Minimum Value From DataGridView Column Using VB NET


vb.net datagridview column minimum value

VB.NET - How To Get The Value Minimum In DataGridView Column Using VB NET

                                                                                                                         

In This VB.NET Tutorial  We Will See How To Get The Minimum Value From DataGridView  Column And Display It In TextBox Using VBNET Programming Language.


Project Source Code:

Public Class VB_Datagridview_Column_Cells_Min_Value

    Private Sub VB_Datagridview_Column_Cells_Min_Value_Load(sender As Object, e As EventArgs) Handles MyBase.Load

       ' populate datagridview with some data
        Dim rand As New Random()
        For i As Integer = 0 To 11 Step +1
            dataGridView1.Rows.Add("First Name" + i.ToString(), "Last Name" + i.ToString(), rand.Next(20, 65).ToString())
        Next
        dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill
        dataGridView1.AllowUserToAddRows = False

        ' Method 1
        textBoxMin.Text = (From row As DataGridViewRow In dataGridView1.Rows
        Where row.Cells(2).FormattedValue.ToString() <> String.Empty
               Select Convert.ToInt32(row.Cells(2).FormattedValue)).Min().ToString()

        ' Method 2
        Dim min As Integer
        For i As Integer = 0 To dataGridView1.Rows.Count() - 1 Step +1
            If i = 0 Then
                min = dataGridView1.Rows(i).Cells(2).Value
            End If

            If min > dataGridView1.Rows(i).Cells(2).Value Then
                min = dataGridView1.Rows(i).Cells(2).Value
            End If
        Next

        textBoxMin.Text = min.ToString()

    End Sub
End Class
      
///////////////OUTPUT:


vb.net datagridview column minimum value
vb datagridview column min value

Bagikan

Jangan lewatkan

VB.NET - How To Get The Minimum Value From DataGridView Column Using VB NET
4/ 5
Oleh

Subscribe via email

Suka dengan artikel di atas? Tambahkan email Anda untuk berlangganan.