Click here to Skip to main content
15,889,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
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 date.today 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.
code
VB
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
Posted
Updated 22-Apr-14 0:49am
v2

1 solution

Use DataGridView1.CurrentRow.Cells("name").Value or
DataGridView1.Rows(DataGridView1.CurrentCell.RowIndex).Cells("name").Value

VB
Dim rowContent As String = String.Empty

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

MessageBox.Show(rowContent)
 
Share this answer
 
v2

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