Click here to Skip to main content
15,922,894 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

VB
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
Posted
Updated 13-Dec-11 21:07pm
v4
Comments
Scubapro 8-Dec-11 2:35am    
Which database en how does your code look like now?
Sander Rossel 8-Dec-11 2:46am    
First, that's not a question. Second, if it was it's a very poorly written one. Third, for anyone to answer this we need more information, what DB are you using? How do you fill your grid? What code do you have so far?
If you expect us to take the trouble to solve your problems at least take the trouble to carefully explain that problem.
Slacker007 14-Dec-11 6:11am    
You don't need to tell the OP their question was poorly written. Report it as such, make edits, or just leave the question alone and move on to the next one. :)
Sander Rossel 14-Dec-11 16:39pm    
This member should see the error of his ways. I'm usually not about reporting or downvoting without giving a decent explanation as to why I did it.
Besides, it has to be said from time to time to set an example for others. Or we'll all get questions like these. I see the OP has edited his question by the way, so I guess my words have been read and got the wished for result: a better question (though I haven't read it yet) :)
Slacker007 15-Dec-11 6:01am    
It is not your place here, on this site, to show someone the error of their ways or to make an example out of someone. Either help them out, without making them look stupid, or move on to another question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900