How to read Rows of a DatagridView through for loop
Hi, My application is in VS2008 coded in Vb.net.I have a datagridview which is populated from Database.I have a save button on the same form that has DatagridView. My requirement is i want that all the records that are populated in DatagridView should be saved in a certain table of the database when the user clicks save. Im done with my save and Update code.What im not able to do is,im not able to increment the counter and move to the next row of datagridView when my For loop is executing after the click of Save button. Below is my Code.
For i As Integer = 0 To DGVStudRecord.RowCount - 1
My code to Update And Save
Next
Here what is happening is when save button is clicked my for Loop is executing and looping till RowCount-1.But i want that after completion of each loop my i should get to the next row in the datagirdView.I should be able to get the values of next row to pass it to my controls that are carrying update and delete operation. The entire data in the datagridview will be saved in a certain table at the click of save button. Please suggest.


Software/Hardware used:
VS2008,vb.net
ASKED: September 10, 2011  2:56 PM
UPDATED: March 31, 2012  4:50 PM

Answer Wiki:
You don't need to modify your Loop, but your code to update and save. Your 'save' code should use 'i' as the row number. For example, to reference the first column of the current row, you would use something like this: <pre>DGVStudRecord.Rows(i).Cells(0).Text</pre>
Last Wiki Answer Submitted:  September 12, 2011  2:36 pm  by  carlosdl   63,535 pts.
All Answer Wiki Contributors:  carlosdl   63,535 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _