Kankichi, why don't you attach images to the post? That way we don't have to wait 2 minutes for the image to load at ImageLack and it won't be gone tomorrow. I attached these two images to your post.
sounds your way is much more easy then mine, cause i can't explain very good in englishWhy not allow the datagridview to be editable, change the information on the datagrid and then have an 'Update' button on the form that will update any changed rows(RowState = Modified)? This is assuming you are updating a database (or some sort of storage) behind this. Then you are only dealing with one form.
Dim dtData as System.Data.DataTable
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Try
dtData = new Datatable
'fill edit table
If Not FillData(sqlWork, dtData) Then
MessageBox.Show("Error trying to fill Grid table.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Try
End If
'now set the grid datasource
DataGridView1.Datasource = dtData
'grid should be loaded
Catch Exp As Exception
MessageBox.Show(Exp.Message, "Error", MessageBoxButtons.OK)
End Try
End Sub
Public Sub btnProcess_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnProcess.Click
Try
Dim drCurrentEditRow As DataRow
'loop through each row in the grid and check for changes
For RowCnt As Integer = 0 To dtData.Rows.Count - 1
drCurrentEditRow = dtData.Rows(RowCnt)
'check for changes
Select Case drCurrentEditRow.RowState
Case DataRowState.Added
InsertRecords(drCurrentEditRow)
Case DataRowState.Deleted
DeleteRecords(drCurrentEditRow)
Case DataRowState.Modified
UpdateRecords(drCurrentEditRow)
Case DataRowState.Unchanged
End Select
Next
Catch exp As System.Exception
MessageBox.Show(Exp.Message, "Error", MessageBoxButtons.OK)
End Try
End Sub
'This is used to fill a datatable from a SQL database.
Public Function FillData(ByVal SQLQueryString As String, ByRef PassDataTable As DataTable) As Boolean
Dim ReturnBool As Boolean = True
Using sqlConn As New SqlConnection(ConnectionString)
Try
PassDataTable = New DataTable
Using cmdSearch As New SqlCommand(SQLQueryString, sqlConn)
Using daGetData As New SqlDataAdapter(cmdSearch)
daGetData.Fill(PassDataTable)
End Using
End Using
Catch exp As Data.SqlClient.SqlException
ReturnBool = False
Catch exp As System.Exception
ReturnBool = False
End Try
End Using
Return ReturnBool
End Function