Link to home
Start Free TrialLog in
Avatar of wiswalld
wiswalldFlag for United States of America

asked on

Change value in datagridview cell

How can I go to a cell 7 and change its value in a datagridview1 where the value in cell 1 equals the value in datagridview2.

Datagridview1

Unit               Date              Available
110               4/4/07            No


Datagridview2

Unit              Name1                 Name2             Cleared
110              Smith                    Doe                 11:00

After I enter a time in the cleared cell of datagridview2 I want the No to change to Yes where Datagridview cell1 = datagridview cell1
Avatar of Priest04
Priest04
Flag of Serbia image

If DataGridView1.Item(columnindex,rowindex).Value = DataGridView1.Item(columnindex,rowindex).Value then
    DataGridView1.Item(columnindex,rowindex).Value = "Yes"
End if

where columnindex/rowindex are the indeces of the cell column/row starting from 0. To get the current column/row index, use

DataGridView1.CurrentCell.Columnindex
DataGridView1.CurrentCell.Rowindex

YOu can use CellEndEdit event of DataGridView to do this comparation, which is fired right after the cell is finished editing.

Goran
Avatar of wiswalld

ASKER

If DataGridView1.Item(columnindex,rowindex).Value = DataGridView2.Item(columnindex,rowindex).Value then
    DataGridView1.Item(columnindex,rowindex).Value = "Yes"
End if

I don't know what the row or column index will be. Could be row 10 in datagridview2 and row 3 in datagridview1. I will need to search Datagridview1 column 0 and find the match to Datagridview2 column zero and then update column seven from Datagridview1 where they match.

Unit               Date              Available
100               4/4/07            Yes
110               4/4/07            No      < Row to match>


Datagridview2

Unit              Name1                 Name2             Cleared
110              Smith                    Doe                 11:00               <Row to match with using 110>

Something like this maybe:

If Me.Datagridview1("unit").Value = Me.datagridview2.CurrentRow.Cells(1).Value Then
            Datagridview1.CurrentRow.Cells(7).Value = "Yes"
        End If

Error here
Me.Datagridview1("unit").
ASKER CERTIFIED SOLUTION
Avatar of Priest04
Priest04
Flag of Serbia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial