I filled my datagrid view through a function ,that is called in the Rowstate event.
when i am trying to save the entire datagridview rows in to the database only the rows displayed on the screen are saved.(If ther are 14 rows in the grid and only 10 is displayed and the other4 rows are in the bottem of the grid.then only the 10 rows are saved )
once i using the scroll bar to looking the rows in the bottom of the grid, then clicking the save button the entire data will be saved.
iam using the below code to fill the datagridview
daCOA = New SqlDataAdapter(coaStr, JDLCommon.ModCommon.strConString)
daCOA.Fill(dsCOA, "tblFind")
If dsCOA.Tables("tblFind").Rows.Count > 0 Then
frm.dgvDetail.Rows.AddCopies(0, dsCOA.Tables("tblFind").Rows.Count)
end if
and calling the GetCellData function in the datagridview RowStateChanged event
<pre lang="vb">Private Sub dgvDetail_RowStateChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowStateChangedEventArgs) Handles dgvDetail.RowStateChanged
Try
If e.Row.Index < 0 Then Exit Sub
If Me.Created = False Then Exit Sub
If e.StateChanged = DataGridViewElementStates.Displayed And dgvDetail.Item("colPmName", e.Row.Index).Value Is Nothing Then
objCOA.GetCellData(e.Row.Index)
End If
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation, JDLCommon.ModCommon.MsgTitle)
End Try
End Sub
Public Sub GetCellData(ByVal row)
Dim i As Integer
Try
If dsCOA.Tables("tblFind") Is Nothing Then Exit Sub
If row < dsCOA.Tables("tblFind").Rows.Count Then
For i = 0 To frm.dgvDetail.Columns.Count - 1
frm.dgvDetail.Item(frm.dgvDetail.Columns(i).Name, row).Value = dsCOA.Tables("tblFind").Rows(row)(frm.dgvDetail.Columns(i).Name)
Next
End If
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation, JDLCommon.ModCommon.MsgTitle)
Finally
End Try
End Sub