Click here to Skip to main content
14,700,165 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to get values from specific cells from a datagridview row which is selected programmatically, I have an application which stores dates and then compare the dates of cells and when the is epual or with in a month less than the cell date to produce a message box, I want to take the other row's cell values of the selected cells (name, car_num etc) and produce them in the message box.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim dt As New Date
        dt = Date.Parse(DataGridView1.CurrentCell.Value)
        TextBox1.Text = DataGridView1.CurrentCell.Value.ToString
        If (Date.Today >= (dt.AddMonths(-1))) And (Date.Today <= dt) Then
            DataGridView1.CurrentCell.Style.BackColor = Color.Beige
            MessageBox.Show("date,car num, name", "date")
        End If
    End Sub
Updated 22-Apr-14 1:49am

1 solution

Use DataGridView1.CurrentRow.Cells("name").Value or

Dim rowContent As String = String.Empty

       For columnCounter As Integer = 0 To DataGridView1.ColumnCount - 1
           rowContent = rowContent & " " & DataGridView1.CurrentRow.Cells(columnCounter).Value.ToString()


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900