How to see if a cell has changed in datagridview

visual basic 2010

I have a datagridview that is bound to a datatable in a book purchasing program I'm working on. I would like to change one field (Vendor) if the user changes another field (Price). Basically the datagridview is populated with the title information and price from one of several wholesalers and if the user changes the price, I want the Vendor field on that record to change to "Custom."

There are only going to be 10 or so records in the datagridview at a time so looping through won't be a problem. I'm just not sure how to see if a specific cell versus the whole row has changed (the user will be making other changes such as quantity that don't require setting the vendor to custom) and then how to change the Vendor field for that row.
berniesbooksAsked:
Who is Participating?
 
CodeCruiserConnect With a Mentor Commented:
In the CellValueChanged Event

If e.ColumnIndex = 2 Then 'This assumes that the cell you are interested in is at 3rd position
   'Modify the other value here
   'datagridview1.Rows(e.RowIndex).Cells(1).Value = "new value"
End If
0
 
sdrouinsCommented:
did you try with
DataGridView.CellValueChanged Event
0
 
berniesbooksAuthor Commented:
With CellValueChanged, how do I tell it to run the event only when the "Price" cell is changed? The user needs to be able to make changes to some of the other cells without triggering the event.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
CodeCruiserCommented:
Use boolean flags and set them in the CellValueChanged event if its the cell you are interested in.
0
 
gamarrojgqCommented:
Hi,

This event is trigger for every cell, so, in the CellValueChanged event you have the e parameter, As System.Windows.Forms.DataGridViewCellEventArgs, this have a ColumnIndex  property that let you know wich cell was changed, so you can valid this to see if is  equal to your Price columnindex and if is different, you just can exit the event.

Hope it helps.
0
 
berniesbooksAuthor Commented:
I apologize, this is my first project working with datagridview. CodeCruiser can you point me to a code sample that sets the boolean flag and then references it in the event?
0
 
berniesbooksAuthor Commented:
Thanks CodeCruiser!

It's a fairly simple solution that I would have spent forever trying to figure out.
0
 
CodeCruiserCommented:
Glad to help :-)
0
All Courses

From novice to tech pro — start learning today.